50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
from blueprints import default_blueprint
|
|
from di_container import Container
|
|
from configs import Config
|
|
from flask import Flask
|
|
from blueprints import auth_blueprint
|
|
from database import init_db
|
|
from authlib.integrations.flask_client import OAuth
|
|
from flask_login import LoginManager
|
|
|
|
|
|
def createApp() -> Flask:
|
|
app = Flask(__name__)
|
|
app.config.from_object(Config)
|
|
container = Container()
|
|
|
|
app.container = container
|
|
|
|
login_manager = LoginManager(app)
|
|
oauth = OAuth(app)
|
|
|
|
google = oauth.register(
|
|
name="google",
|
|
client_id=app.config["GOOGLE_CLIENT_ID"],
|
|
client_secret=app.config["GOOGLE_CLIENT_SECRET"],
|
|
access_token_url=app.config["GOOGLE_TOKEN_URI"],
|
|
authorize_url=app.config["GOOGLE_AUTH_URI"],
|
|
api_base_url=app.config["GOOGLE_BASE_URL"],
|
|
client_kwargs={"scope": "openid email profile"},
|
|
)
|
|
|
|
if google is not None:
|
|
container.google_auth.override(google)
|
|
|
|
mongo = init_db(app)
|
|
if mongo is not None:
|
|
container.mongo.override(mongo)
|
|
|
|
container.wire(modules=["blueprints.auth"])
|
|
|
|
# Register Blueprints
|
|
app.register_blueprint(default_blueprint)
|
|
app.register_blueprint(auth_blueprint, url_prefix="/api")
|
|
|
|
return app
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = createApp()
|
|
app.run(host="0.0.0.0", debug=Config.DEBUG)
|