Update: remove unused imports, added better comments and refactored for all blueprints

This commit is contained in:
white
2025-01-27 12:49:42 +00:00
parent 3dc44da69a
commit 4e9fa011fa
8 changed files with 96 additions and 74 deletions

View File

@@ -1,16 +1,27 @@
from flask import Flask
# from flask_wtf.csrf import CSRFProtect, generate_csrf
from flask_session import Session
from blueprints.utils import logged_in_user
from flask_cors import CORS
import os
from blueprints.utils import logged_in_user
# from flask_wtf.csrf import CSRFProtect, generate_csrf
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, socketio
from os import getenv
# csrf = CSRFProtect()
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["SECRET_KEY"] = os.getenv("FLASK_SECRET_KEY")
app.config["SECRET_KEY"] = getenv("FLASK_SECRET_KEY")
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
#! ↓↓↓ For development purposes only - Allow cross-origin requests for the frontend
@@ -25,16 +36,9 @@ def create_app():
# return jsonify({'csrf_token': generate_csrf()}), 200
with app.app_context():
from blueprints.authentication import auth_bp
from blueprints.main import main_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, socketio
# Registering Blueprints
app.register_blueprint(auth_bp)
app.register_blueprint(main_bp)
app.register_blueprint(stripe_bp)
app.register_blueprint(user_bp)
app.register_blueprint(stream_bp)