* Fix pylint warnings across all 24 Python files in web_server - Add module, class, and function docstrings (C0114, C0115, C0116) - Fix import ordering: stdlib before third-party before local (C0411) - Replace wildcard imports with explicit named imports (W0401) - Remove trailing whitespace and add missing final newlines (C0303, C0304) - Replace dict() with dict literals (R1735) - Remove unused imports and variables (W0611, W0612) - Narrow broad Exception catches to specific exceptions (W0718) - Replace f-string logging with lazy % formatting (W1203) - Fix variable naming: UPPER_CASE for constants, snake_case for locals (C0103) - Add pylint disable comments for necessary global statements (W0603) - Fix no-else-return, simplifiable-if-expression, singleton-comparison - Fix bad indentation in stripe.py (W0311) - Add encoding="utf-8" to open() calls (W1514) - Add check=True to subprocess.run() calls (W1510) - Register Celery task modules via conf.include * Update `package-lock.json` add peer dependencies
73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
"""Flask application factory and blueprint registration."""
|
|
|
|
from os import getenv
|
|
|
|
from flask import Flask
|
|
from flask_session import Session
|
|
from flask_cors import CORS
|
|
|
|
from blueprints.middleware import logged_in_user, register_error_handlers
|
|
from blueprints.authentication import auth_bp
|
|
from blueprints.stripe import stripe_bp
|
|
from blueprints.user import user_bp
|
|
from blueprints.streams import stream_bp
|
|
from blueprints.chat import chat_bp
|
|
from blueprints.admin import admin_bp
|
|
from blueprints.oauth import oauth_bp, init_oauth
|
|
from blueprints.socket import socketio
|
|
from blueprints.search_bar import search_bp
|
|
|
|
from celery_tasks import celery_init_app
|
|
|
|
|
|
def create_app():
|
|
"""
|
|
Set up the flask app by registering all the blueprints and configuring
|
|
the settings. Also create a CSRF token to prevent Cross-site Request Forgery.
|
|
And setup web sockets to be used throughout the project.
|
|
"""
|
|
app = Flask(__name__)
|
|
app.config["SERVER_NAME"] = getenv("HOMEPAGE_URL")
|
|
app.config["SECRET_KEY"] = getenv("FLASK_SECRET_KEY")
|
|
app.config["SESSION_PERMANENT"] = False
|
|
app.config["SESSION_TYPE"] = "filesystem"
|
|
app.config["PROPAGATE_EXCEPTIONS"] = True
|
|
app.config['GOOGLE_CLIENT_ID'] = getenv("GOOGLE_CLIENT_ID")
|
|
app.config['GOOGLE_CLIENT_SECRET'] = getenv("GOOGLE_CLIENT_SECRET")
|
|
app.config["SESSION_COOKIE_HTTPONLY"] = True
|
|
|
|
app.config.from_mapping(
|
|
CELERY={
|
|
"broker_url": "redis://redis:6379/0",
|
|
"result_backend": "redis://redis:6379/0",
|
|
"task_ignore_result": True,
|
|
},
|
|
)
|
|
app.config.from_prefixed_env()
|
|
celery_init_app(app)
|
|
|
|
#! ↓↓↓ For development purposes only - Allow cross-origin requests for the frontend
|
|
CORS(app, supports_credentials=True)
|
|
|
|
socketio.init_app(app) # create socket connection
|
|
Session(app)
|
|
app.before_request(logged_in_user) # check user is logged in
|
|
init_oauth(app)
|
|
register_error_handlers(app) # adds in error handlers
|
|
|
|
with app.app_context():
|
|
|
|
# Registering Blueprints
|
|
app.register_blueprint(auth_bp)
|
|
app.register_blueprint(stripe_bp)
|
|
app.register_blueprint(user_bp)
|
|
app.register_blueprint(stream_bp)
|
|
app.register_blueprint(chat_bp)
|
|
app.register_blueprint(oauth_bp)
|
|
app.register_blueprint(search_bp)
|
|
app.register_blueprint(admin_bp)
|
|
|
|
socketio.init_app(app)
|
|
|
|
return app
|