50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
import os
|
|
from datetime import timedelta
|
|
|
|
from flask import Flask
|
|
from flask_jwt_extended import JWTManager
|
|
|
|
from app.services.auth_service import AuthService
|
|
from app.database import init_db
|
|
|
|
# Global auth service instance
|
|
auth_service = AuthService()
|
|
|
|
|
|
def create_app():
|
|
"""Create and configure the Flask application."""
|
|
app = Flask(__name__)
|
|
|
|
# Configure Flask secret key (required for sessions used by OAuth)
|
|
app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", "dev-secret-key")
|
|
|
|
# Configure SQLAlchemy database
|
|
database_url = os.environ.get("DATABASE_URL", "sqlite:///soundboard.db")
|
|
app.config["SQLALCHEMY_DATABASE_URI"] = database_url
|
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
|
|
|
# Configure Flask-JWT-Extended
|
|
app.config["JWT_SECRET_KEY"] = os.environ.get("JWT_SECRET_KEY", "jwt-secret-key")
|
|
app.config["JWT_ACCESS_TOKEN_EXPIRES"] = timedelta(minutes=15)
|
|
app.config["JWT_REFRESH_TOKEN_EXPIRES"] = timedelta(days=7)
|
|
app.config["JWT_TOKEN_LOCATION"] = ["cookies"]
|
|
app.config["JWT_COOKIE_SECURE"] = False # Set to True in production
|
|
app.config["JWT_COOKIE_CSRF_PROTECT"] = False
|
|
app.config["JWT_ACCESS_COOKIE_PATH"] = "/api/"
|
|
app.config["JWT_REFRESH_COOKIE_PATH"] = "/api/auth/refresh"
|
|
|
|
# Initialize JWT manager
|
|
jwt = JWTManager(app)
|
|
|
|
# Initialize database
|
|
init_db(app)
|
|
|
|
# Initialize authentication service with app
|
|
auth_service.init_app(app)
|
|
|
|
# Register blueprints
|
|
from app.routes import main, auth
|
|
app.register_blueprint(main.bp, url_prefix="/api")
|
|
app.register_blueprint(auth.bp, url_prefix="/api/auth")
|
|
|
|
return app |