一个功能完整的短链接生成和管理API服务,包含MySQL + Redis + API的一体化容器。
# 下载并运行一键脚本
curl -O https://raw.githubusercontent.com/nodesire7/short_url/main/start-single.sh
chmod +x start-single.sh
./start-single.sh
# 下载配置文件
curl -O https://raw.githubusercontent.com/nodesire7/short_url/main/docker-compose.single.yml
# 设置API Token
export API_TOKEN=$(openssl rand -hex 32)
# 启动服务
docker-compose -f docker-compose.single.yml up -d
echo "API Token: $API_TOKEN"
echo "服务地址: http://localhost:2282"
| 变量名 | 默认值 | 说明 |
|---|---|---|
API_TOKEN | 必需 | API认证令牌(自动生成) |
BASE_URL | http://localhost:2282 | 服务基础URL |
SHORT_CODE_LENGTH | 6 | 短代码长度 |
LOG_LEVEL | INFO | 日志级别 |
所有API请求需要在Header中包含API Token:
Authorization: YOUR_API_TOKEN
curl -X POST http://localhost:2282/api/create \
-H "Authorization: YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"url": "https://www.example.com",
"title": "示例网站",
"code": "custom"
}'
响应示例:
{
"success": true,
"short_code": "custom",
"short_url": "https://s.gbtgame.me/custom",
"original_url": "https://www.example.com",
"title": "示例网站",
"created_at": "2025-06-25T16:30:00",
"qr_code": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}
curl -X GET "http://localhost:2282/api/list?page=1&limit=20" \
-H "Authorization: YOUR_API_TOKEN"
curl -X GET http://localhost:2282/api/info/abc123 \
-H "Authorization: YOUR_API_TOKEN"
curl -X DELETE http://localhost:2282/api/delete/abc123 \
-H "Authorization: YOUR_API_TOKEN"
curl -X GET http://localhost:2282/api/stats \
-H "Authorization: YOUR_API_TOKEN"
curl -X DELETE http://localhost:2282/api/clear \
-H "Authorization: YOUR_API_TOKEN"
curl http://localhost:2282/health
# 查看服务状态
docker-compose -f docker-compose.single.yml ps
# 查看日志
docker-compose -f docker-compose.single.yml logs -f
# 重启服务
docker-compose -f docker-compose.single.yml restart
# 停止服务
docker-compose -f docker-compose.single.yml down
欢迎提交Issue和Pull Request!
MIT License
Content type
Image
Digest
sha256:10de0faf9…
Size
279.3 MB
Last updated
9 months ago
docker pull nodesire77/shorturl_api