chore: sync local changes (2026-03-12)

This commit is contained in:
2026-03-12 18:58:40 +08:00
parent 1123d6aef2
commit 4cc8ec9486
21 changed files with 4561 additions and 270 deletions

View File

@@ -0,0 +1,41 @@
# Docker 相关文件
.dockerignore
# Node
node_modules/
npm-debug.log
yarn-error.log
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
*.egg-info/
# 构建产物
dist/
build/
# IDE
.vscode/
.idea/
*.swp
*.swo
# OS
.DS_Store
Thumbs.db
# Git
.git/
.gitignore
# 文档
README.md
*.md
# 配置
.env
.env.local

View File

@@ -0,0 +1,20 @@
# 纯后端Docker镜像前端单独部署
FROM python:3.11-slim
WORKDIR /app
# 复制后端文件
COPY . .
# 安装 Python 依赖
RUN pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir gunicorn
# 创建持久化数据目录
RUN mkdir -p /app/data
# 暴露端口
EXPOSE 7878
# 启动服务使用gunicorn
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7878", "app:app"]

View File

@@ -7,9 +7,20 @@ import string
from datetime import datetime, timedelta
app = Flask(__name__)
CORS(app)
# 配置CORS允许前端服务器访问
CORS(app, origins=[
"http://192.168.1.100:8989", # 前端服务器
"http://localhost:8989", # 本地测试
"http://127.0.0.1:8989", # 本地测试
"http://short.shumengya.top", # 前端域名(如果有)
"https://short.shumengya.top" # 前端域名HTTPS如果有
])
DATA_FILE = 'link_data.json'
# 数据文件路径(支持持久化挂载)
DATA_DIR = os.getenv('DATA_DIR', '/app/data')
if not os.path.exists(DATA_DIR):
os.makedirs(DATA_DIR)
DATA_FILE = os.path.join(DATA_DIR, 'link_data.json')
def load_links():
"""加载链接数据"""

View File

@@ -0,0 +1,19 @@
services:
mengyalinkfly-backend:
build: .
container_name: mengyalinkfly-backend
ports:
- "7878:7878"
volumes:
# 数据持久化目录
- /shumengya/docker/mengyalinkfly:/app/data
restart: unless-stopped
environment:
- TZ=Asia/Shanghai
- PYTHONUNBUFFERED=1
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:7878/ || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s

View File

@@ -0,0 +1,39 @@
#!/bin/bash
# 后端Docker部署脚本
echo "========== 萌芽短链后端部署 =========="
# 停止并删除旧容器
echo "停止旧容器..."
docker stop mengyalinkfly-backend 2>/dev/null
docker rm mengyalinkfly-backend 2>/dev/null
# 构建新镜像
echo "构建Docker镜像..."
docker build -t mengyalinkfly-backend:latest .
# 创建数据目录
echo "创建数据目录..."
mkdir -p /shumengya/docker/storage/mengyalinkfly
# 运行容器
echo "启动Docker容器..."
docker run -d \
--name mengyalinkfly-backend \
-p 7878:7878 \
-v /shumengya/docker/storage/mengyalinkfly:/app/data \
-e TZ=Asia/Shanghai \
--restart unless-stopped \
mengyalinkfly-backend:latest
# 检查状态
echo ""
echo "========== 部署完成 =========="
echo "容器状态:"
docker ps | grep mengyalinkfly-backend
echo ""
echo "查看日志:"
echo "docker logs -f mengyalinkfly-backend"
echo ""
echo "后端API地址http://localhost:7878"