37 lines
842 B
Python
37 lines
842 B
Python
![]() |
from flask import Flask,jsonify
|
||
|
from flask_sqlalchemy import SQLAlchemy
|
||
|
from flask_migrate import Migrate # type: ignore
|
||
|
from config import Config
|
||
|
from flask_cors import CORS
|
||
|
|
||
|
db = SQLAlchemy()
|
||
|
migrate = Migrate()
|
||
|
|
||
|
|
||
|
def create_app():
|
||
|
app = Flask(__name__)
|
||
|
|
||
|
CORS(app)
|
||
|
|
||
|
app.config.from_object(Config)
|
||
|
|
||
|
# 初始化数据库
|
||
|
db.init_app(app)
|
||
|
migrate.init_app(app, db)
|
||
|
|
||
|
# 添加根路由
|
||
|
@app.route('/')
|
||
|
def home():
|
||
|
return jsonify({"status": "success", "message": "Welcome to the API!"})
|
||
|
|
||
|
# 注册蓝图
|
||
|
|
||
|
from app.routes import session_routes, user_routes, message_routes, report_routes
|
||
|
# 注册路由
|
||
|
app.register_blueprint(session_routes)
|
||
|
app.register_blueprint(message_routes)
|
||
|
app.register_blueprint(report_routes)
|
||
|
app.register_blueprint(user_routes)
|
||
|
|
||
|
return app
|