45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from flask import Flask, send_from_directory
|
|
from flask_cors import CORS
|
|
from models import db, Task, TimeRecord
|
|
from routes import api
|
|
import os
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
|
|
# 配置
|
|
app.config['SECRET_KEY'] = 'your-secret-key-here-change-in-production'
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///worklist.db'
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
|
|
# Session配置
|
|
app.config['SESSION_COOKIE_SAMESITE'] = 'Lax'
|
|
app.config['SESSION_COOKIE_HTTPONLY'] = True
|
|
app.config['PERMANENT_SESSION_LIFETIME'] = 86400 # 24小时
|
|
|
|
# 初始化扩展
|
|
db.init_app(app)
|
|
CORS(app, supports_credentials=True) # 允许跨域请求并支持凭证
|
|
|
|
# 注册蓝图
|
|
app.register_blueprint(api, url_prefix='/api')
|
|
|
|
# 创建数据库表
|
|
with app.app_context():
|
|
db.create_all()
|
|
|
|
# 静态文件服务(用于前端)
|
|
@app.route('/')
|
|
def index():
|
|
return send_from_directory('../frontend', 'index.html')
|
|
|
|
@app.route('/<path:filename>')
|
|
def static_files(filename):
|
|
return send_from_directory('../frontend', filename)
|
|
|
|
return app
|
|
|
|
if __name__ == '__main__':
|
|
app = create_app()
|
|
app.run(debug=True, host='0.0.0.0', port=5000)
|