feat: v2.0.0 - 合并后台管理到单端口
- 端口从 19011+19012 合并为 19011 - 前台API: http://localhost:19011 - 后台管理: http://localhost:19011/admin - 新增 templates 目录,整合管理页面模板 - 更新所有路由为 /admin 路径
This commit is contained in:
70
app.py
70
app.py
@@ -1,8 +1,13 @@
|
||||
"""
|
||||
产品参数爬取系统 - 主程序
|
||||
v2.0.0 - 合并后台管理到单端口
|
||||
|
||||
端口: 19011
|
||||
前台: http://localhost:19011
|
||||
后台: http://localhost:19011/admin
|
||||
"""
|
||||
|
||||
from flask import Flask, jsonify, request
|
||||
from flask import Flask, jsonify, request, render_template
|
||||
from flask_cors import CORS
|
||||
import json
|
||||
import os
|
||||
@@ -18,7 +23,7 @@ logging.basicConfig(
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
app = Flask(__name__)
|
||||
app = Flask(__name__, template_folder='templates')
|
||||
CORS(app)
|
||||
|
||||
# 路径配置
|
||||
@@ -59,20 +64,21 @@ def save_tasks(data):
|
||||
TASKS_FILE.write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
|
||||
|
||||
# ============ API 路由 ============
|
||||
# ============ 前台 API 路由 ============
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
"""首页"""
|
||||
"""前台首页 - API说明"""
|
||||
return jsonify({
|
||||
"name": "Product Crawler",
|
||||
"version": "1.0.0",
|
||||
"version": "2.0.0",
|
||||
"description": "产品参数爬取系统",
|
||||
"endpoints": {
|
||||
"products": "/api/products",
|
||||
"tasks": "/api/tasks",
|
||||
"spiders": "/api/spiders",
|
||||
"run": "/api/run/<spider_name>"
|
||||
"run": "/api/run/<spider_name>",
|
||||
"admin": "/admin"
|
||||
}
|
||||
})
|
||||
|
||||
@@ -326,12 +332,60 @@ def api_export():
|
||||
return jsonify({"error": "Unsupported format"}), 400
|
||||
|
||||
|
||||
# ============ 后台管理页面路由 ============
|
||||
|
||||
@app.route('/admin')
|
||||
def admin_index():
|
||||
"""后台首页"""
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
@app.route('/admin/products')
|
||||
def admin_products():
|
||||
"""后台 - 产品管理"""
|
||||
return render_template('products.html')
|
||||
|
||||
|
||||
@app.route('/admin/spiders')
|
||||
def admin_spiders():
|
||||
"""后台 - 爬虫管理"""
|
||||
return render_template('spiders.html')
|
||||
|
||||
|
||||
@app.route('/admin/tasks')
|
||||
def admin_tasks():
|
||||
"""后台 - 任务管理"""
|
||||
return render_template('tasks.html')
|
||||
|
||||
|
||||
@app.route('/admin/config')
|
||||
def admin_config():
|
||||
"""后台 - 配置管理"""
|
||||
return render_template('config.html')
|
||||
|
||||
|
||||
# ============ 后台管理 API(统计) ============
|
||||
|
||||
@app.route('/api/admin/stats')
|
||||
def api_admin_stats():
|
||||
"""后台统计信息"""
|
||||
data = load_products()
|
||||
tasks = load_tasks().get("tasks", [])
|
||||
|
||||
return jsonify({
|
||||
"total_products": len(data.get("products", [])),
|
||||
"last_update": data.get("last_update"),
|
||||
"total_tasks": len(tasks),
|
||||
"running_tasks": len([t for t in tasks if t.get("status") == "running"])
|
||||
})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("=" * 60)
|
||||
print("产品参数爬取系统")
|
||||
print("产品参数爬取系统 v2.0.0")
|
||||
print("=" * 60)
|
||||
print(f"API地址: http://localhost:19011")
|
||||
print(f"后台管理: http://localhost:19012")
|
||||
print(f"后台管理: http://localhost:19011/admin")
|
||||
print("=" * 60)
|
||||
|
||||
app.run(host='0.0.0.0', port=19011, debug=True)
|
||||
Reference in New Issue
Block a user