init
This commit is contained in:
39
backend/app.py
Normal file
39
backend/app.py
Normal file
@@ -0,0 +1,39 @@
|
||||
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'
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///worklist.db'
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
|
||||
# 初始化扩展
|
||||
db.init_app(app)
|
||||
CORS(app) # 允许跨域请求
|
||||
|
||||
# 注册蓝图
|
||||
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)
|
||||
Reference in New Issue
Block a user