An Express-like HTTP router for Bash compatible with CGI 1.1
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.2 KiB

2 years ago
# Exprash
An Express-like HTTP router for Bash compatible with CGI 1.1
I'm aware that the name of this project evokes a feeling of physical disgust. That is by design.
## Usage/Examples
Here is some leaked source code for my brand new Cat website. Do not steal!
```shell
#!/bin/bash
2 years ago
source exprash.sh;
2 years ago
redirect_stdout 'log';
2 years ago
declare -A cats;
cats[calico]="Calico";
cats[sphynx]="Sphynx";
cats[ragdoll]="Ragdoll";
cats[holland_lop]="Holland Lop";
2 years ago
cats[scottish_fold]="Scottish Fold";
cats[orange]="Orange";
2 years ago
get '/' && {
html='<h1>Cats</h1><ul>';
2 years ago
for key in "${!cats[@]}"; do
html+="<li><a href=\"cats/${key}\">${cats[$key]}</a></li>";
2 years ago
done
html+='</ul>';
printf '%s' "$html" | send;
2 years ago
}
get '/cats/:cat' && {
key=$(param 'cat');
if [[ -v "cats[$key]" ]]; then
if [ "$key" == 'holland_lop' ]; then
next "That's not a cat!";
else
printf '<h1>Your Cat: %s</h1>\n' "${cats[$key]}" | send;
fi;
2 years ago
else
next;
fi;
}
get '/cats/*' && {
printf '<h1>Error: Cannot find that cat</h1>\n' | send;
}
get_error '/cats/*' && {
printf '<h1>%s</h1>' "$(get_error_message)" | send;
}
(use || use_error) && {
printf '<h1>404</h1>' | send;
2 years ago
}
```
## License
[WTFPL](http://www.wtfpl.net/txt/copying/)