53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
from di_container import Container
|
|
from configs import Config, LoggerConfig
|
|
from flask import Flask
|
|
from blueprints import auth_blueprint, user_blueprint, quiz_bp, default_blueprint
|
|
from database import init_db
|
|
import logging
|
|
|
|
|
|
def createApp() -> Flask:
|
|
app = Flask(__name__)
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
|
|
)
|
|
app.config.from_object(Config)
|
|
LoggerConfig.init_logger(app)
|
|
|
|
container = Container()
|
|
|
|
app.container = container
|
|
|
|
mongo = init_db(app)
|
|
if mongo is not None:
|
|
container.mongo.override(mongo)
|
|
|
|
# container.wire(modules=["blueprints.auth"])
|
|
# container.wire(modules=["blueprints.user"])
|
|
# container.wire(modules=["blueprints.quiz"])
|
|
|
|
container.wire(
|
|
modules=[
|
|
"blueprints.auth",
|
|
"blueprints.user",
|
|
"blueprints.quiz",
|
|
]
|
|
)
|
|
|
|
# Register Blueprints
|
|
app.register_blueprint(default_blueprint)
|
|
app.register_blueprint(auth_blueprint, url_prefix="/api")
|
|
app.register_blueprint(user_blueprint, url_prefix="/api")
|
|
app.register_blueprint(quiz_bp, url_prefix="/api/quiz")
|
|
|
|
for rule in app.url_map.iter_rules():
|
|
print(f"Route: {rule} -> Methods: {rule.methods}")
|
|
|
|
return app
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = createApp()
|
|
app.run(host="0.0.0.0", debug=Config.DEBUG)
|