37 lines
837 B
Python
37 lines
837 B
Python
|
|
from flask import Flask
|
||
|
|
from config import Config
|
||
|
|
from extensions import cors, db, jwt
|
||
|
|
from blueprints.user import user_bp
|
||
|
|
from blueprints.auth import auth_bp
|
||
|
|
from common.exceptions import BusinessException
|
||
|
|
from common.response import error
|
||
|
|
|
||
|
|
def create_app():
|
||
|
|
app = Flask(__name__)
|
||
|
|
app.config.from_object(Config)
|
||
|
|
|
||
|
|
cors.init_app(app)
|
||
|
|
db.init_app(app)
|
||
|
|
jwt.init_app(app)
|
||
|
|
|
||
|
|
app.register_blueprint(user_bp)
|
||
|
|
app.register_blueprint(auth_bp)
|
||
|
|
|
||
|
|
@app.errorhandler(BusinessException)
|
||
|
|
def handle_business_exception(e):
|
||
|
|
return error(e.code, e.message)
|
||
|
|
|
||
|
|
@app.errorhandler(Exception)
|
||
|
|
def handle_exception(e):
|
||
|
|
return error(50000, "Internal Server Error")
|
||
|
|
|
||
|
|
with app.app_context():
|
||
|
|
db.create_all()
|
||
|
|
|
||
|
|
return app
|
||
|
|
|
||
|
|
app = create_app()
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
app.run(port=5000)
|