27 lines
839 B
Python
27 lines
839 B
Python
from flask import Flask, request, g
|
|
from flask_cors import CORS
|
|
from .routes import auth_bp, order_bp
|
|
import time
|
|
from datetime import datetime
|
|
|
|
def create_app():
|
|
app = Flask(__name__, static_folder="../static", template_folder="../templates")
|
|
app.config['SECRET_KEY'] = 'your-secret-key'
|
|
CORS(app)
|
|
|
|
# 添加性能监控中间件
|
|
@app.before_request
|
|
def before_request():
|
|
g.start_time = time.time()
|
|
|
|
@app.after_request
|
|
def after_request(response):
|
|
if hasattr(g, 'start_time'):
|
|
duration = round((time.time() - g.start_time) * 1000, 2)
|
|
app.logger.info(f"[{datetime.now()}] {request.method} {request.path} - {duration}ms")
|
|
return response
|
|
|
|
app.register_blueprint(auth_bp)
|
|
app.register_blueprint(order_bp, url_prefix='/orders')
|
|
return app
|