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目錄