1.0.5 • Published 8 years ago
easy-cgi v1.0.5
Easily create a CGI server
Installation
- Install Node.js
- Install easy-cgi
npm install -g easy-cgiExample (Using Bash)
Create a directory for your app whith your CGI executable files.
App directory
app
└---hello.shapp/hello.sh
#!/bin/sh
# Headers are written first. The special "Status"
# header indicates the response status code
echo "Status: 200"
echo "Content-Type: text/plain"
echo
# Followed by a response body
echo "Hello World!"Give execute permissions to the file
chmod +x hello.shThen start your CGI server
cgiAccess the address http://localhost:8080/hello in the browser
Routing
The routes are created automatically by file name
Example:
- For the
app/hello.shfile, the route is/hello - For the
app/foo/bar.shfile, the route is/foo/bar - For the
app/index.shfile, the route is/ - For the
app/foo/index.shfile, the route is/foo
If you create a
app/srcdirectory, it will be ignored
Dynamic routes
Dynamic routes are created adding underscore in file name or directory
Example:
- For the
app/users/_id.shfile, the route is/users/<id> - For the
app/_foo/bar.shfile, the route is/<foo>/bar
Get request values
You can access the request values through the REQUEST environment variable in JSON format
The REQUEST environment variable looks like
{
"body": {},
"params": {},
"query": {},
"headers": {},
"files": {}
}No sessions are supported yet
Static files
To serve static files, create a static directory
