50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
from flask import Flask
|
|
from flask_cors import CORS
|
|
from flask_jwt_extended import JWTManager
|
|
from datetime import timedelta
|
|
import os
|
|
from database import db
|
|
|
|
# 初始化扩展
|
|
jwt = JWTManager()
|
|
|
|
def create_app():
|
|
app = Flask(__name__)
|
|
|
|
# 配置
|
|
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', 'dev-secret-key')
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv(
|
|
'DATABASE_URL',
|
|
'mysql+pymysql://wqf_server_monitor:iwaA7WAirswiwbRb@47.96.181.224:3306/wqf_server_monitor'
|
|
)
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
app.config['JWT_SECRET_KEY'] = os.getenv('JWT_SECRET_KEY', 'jwt-secret-key')
|
|
app.config['JWT_ACCESS_TOKEN_EXPIRES'] = timedelta(hours=24)
|
|
|
|
# 初始化扩展
|
|
db.init_app(app)
|
|
jwt.init_app(app)
|
|
CORS(app)
|
|
|
|
# 注册蓝图
|
|
from routes.auth import auth_bp
|
|
from routes.servers import servers_bp
|
|
from routes.scripts import scripts_bp
|
|
from routes.execute import execute_bp
|
|
from routes.users import users_bp
|
|
|
|
app.register_blueprint(auth_bp, url_prefix='/api/auth')
|
|
app.register_blueprint(servers_bp, url_prefix='/api/servers')
|
|
app.register_blueprint(scripts_bp, url_prefix='/api/scripts')
|
|
app.register_blueprint(execute_bp, url_prefix='/api/execute')
|
|
app.register_blueprint(users_bp, url_prefix='/api/users')
|
|
|
|
# 创建数据表
|
|
with app.app_context():
|
|
db.create_all()
|
|
|
|
return app
|
|
|
|
if __name__ == '__main__':
|
|
app = create_app()
|
|
app.run(debug=True, host='0.0.0.0', port=5000) |