https://github.com/azzgo/cgi-web-quickstart
Personal Use, For Quick Proof of Concetp
https://github.com/azzgo/cgi-web-quickstart
cgi-server skeleton
Last synced: about 14 hours ago
JSON representation
Personal Use, For Quick Proof of Concetp
- Host: GitHub
- URL: https://github.com/azzgo/cgi-web-quickstart
- Owner: azzgo
- Created: 2025-12-26T06:52:40.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-12-26T08:17:47.000Z (7 months ago)
- Last Synced: 2026-06-28T18:29:43.595Z (16 days ago)
- Topics: cgi-server, skeleton
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CGI Quick Start
轻量级POC和工具开发脚手架,基于 CGI + Shell Script + JavaScript。
## 快速开始
```bash
./run.sh
```
服务器在 http://127.0.0.1:8080 启动。
## 项目结构
```
cgi-bin/ # 后端 CGI 脚本
main.cgi # 路由入口
config.sh # 配置管理
utils.sh # 工具函数
modules/ # 业务模块
web/ # 前端资源
index.html # 入口页面
.env # 配置文件
run.sh # 启动脚本
```
## 添加功能模块
1. 在 `cgi-bin/modules/` 创建新的 `.sh` 文件
2. 实现 `handle_request()` 函数
3. 在前端 `operations.js` 注册对应操作
### 模块示例
```bash
#!/bin/bash
handle_request() {
local request_body="$1"
local operation=$(parse_json "$request_body" "operation")
case "$operation" in
"test") json_success "测试成功" ;;
*) json_error "未知操作" ;;
esac
}
```
## API 工具函数
```bash
# JSON 处理
parse_json "$json" "key"
json_success "$message" "$data"
json_error "$message"
# 安全验证
validate_input "$input" $max_len
safe_path "$path"
# 日志记录
log_info "$message"
log_error "$message"
```
## Web 端调用
```javascript
api
.call("example", {
operation: "hello",
name: "world",
})
.then((result) => {
console.log("return response is: ", result);
});
```
## 配置 (.env)
```bash
PORT=8080
HOST=127.0.0.1
DEBUG=true
APP_NAME="CGI Quick Start"
```
## 常见问题
- 权限问题:`chmod +x cgi-bin/*.cgi cgi-bin/modules/*.sh`
- 端口占用:`./run.sh -p 3000`