An open API service indexing awesome lists of open source software.

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

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`