#!/bin/bash
source exprash.sh;
redirectStdout 'log';
declare -A cats;
cats[calico]="Calico";
cats[sphynx]="Sphynx";
cats[ragdoll]="Ragdoll";
cats[holland_lop]="Holland Lop";
cats[scottish_fold]="Scottish Fold";
cats[orange]="Orange";
get '/' && {
html='
Cats
';
for key in "${!cats[@]}"; do
html+="- ${cats[$key]}
";
done
html+='
';
printf '%s' "$html" | send;
}
get '/cats/:cat' && {
key=$(param 'cat');
if [[ -v "cats[$key]" ]]; then
if [ "$key" == 'holland_lop' ]; then
next "That's not a cat!";
else
printf 'Your Cat: %s
\n' "${cats[$key]}" | send;
fi;
else
next;
fi;
}
get '/cats/*' && {
printf 'Error: Cannot find that cat
\n' | send;
}
getError '/cats/*' && {
printf '%s
' "$(errorMessage)" | send;
}
(use || useError) && {
printf '404
' | send;
}