MCPcopy Create free account
hub / github.com/HisMax/RedInk / create_app

Function create_app

backend/app.py:38–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36
37
38def create_app():
39 # 设置日志
40 logger = setup_logging()
41 logger.info("🚀 正在启动 红墨 AI图文生成器...")
42
43 # 检查是否存在前端构建产物(Docker 环境)
44 frontend_dist = Path(__file__).parent.parent / 'frontend' / 'dist'
45 if frontend_dist.exists():
46 logger.info("📦 检测到前端构建产物,启用静态文件托管模式")
47 app = Flask(
48 __name__,
49 static_folder=str(frontend_dist),
50 static_url_path=''
51 )
52 else:
53 logger.info("🔧 开发模式,前端请单独启动")
54 app = Flask(__name__)
55
56 app.config.from_object(Config)
57
58 CORS(app, resources={
59 r"/api/*": {
60 "origins": Config.CORS_ORIGINS,
61 "methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
62 "allow_headers": ["Content-Type"],
63 }
64 })
65
66 # 注册所有 API 路由
67 register_routes(app)
68
69 # 启动时验证配置
70 _validate_config_on_startup(logger)
71
72 # 根据是否有前端构建产物决定根路由行为
73 if frontend_dist.exists():
74 @app.route('/')
75 def serve_index():
76 return send_from_directory(app.static_folder, 'index.html')
77
78 # 处理 Vue Router 的 HTML5 History 模式
79 @app.errorhandler(404)
80 def fallback(e):
81 return send_from_directory(app.static_folder, 'index.html')
82 else:
83 @app.route('/')
84 def index():
85 return {
86 "message": "红墨 AI图文生成器 API",
87 "version": "0.1.0",
88 "endpoints": {
89 "health": "/api/health",
90 "outline": "POST /api/outline",
91 "generate": "POST /api/generate",
92 "images": "GET /api/images/<filename>"
93 }
94 }
95

Callers 2

appFunction · 0.90
app.pyFile · 0.85

Calls 3

register_routesFunction · 0.90
setup_loggingFunction · 0.85

Tested by 1

appFunction · 0.72