easy cgi
1.0.0
npm install -g easy-cgi
为您的CGI可执行文件创建一个目录。
应用目录
app
└---hello.sh
app/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! "给出文件的执行权限
chmod +x hello.sh然后启动您的CGI服务器
cgi访问地址http:// localhost:8080/hello在浏览器中
路由是通过文件名自动创建的
例子:
app/hello.sh文件,路由是/helloapp/foo/bar.sh文件,路由为/foo/barapp/index.sh文件,路由为/app/foo/index.sh文件,路由为/foo如果您创建一个
app/src目录,将被忽略
创建动态路线,在文件名或目录中添加下划线
例子:
app/users/_id.sh文件,路由为/users/<id>app/_foo/bar.sh文件,路由为/<foo>/bar您可以以JSON格式的请求环境变量访问请求值
请求环境变量看起来像
{
"body" : {},
"params" : {},
"query" : {},
"headers" : {},
"files" : {}
}尚未支持会议
要提供静态文件,请创建一个static目录