batman
This commit is contained in:
commit
66f9ce3614
33 changed files with 2271 additions and 0 deletions
62
app/__init__.py
Normal file
62
app/__init__.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
"""
|
||||
NetViz application factory.
|
||||
"""
|
||||
import os
|
||||
from flask import Flask
|
||||
from flask_talisman import Talisman
|
||||
from flask_seasurf import SeaSurf
|
||||
|
||||
from app.extensions import db, migrate, login_manager, limiter, mail, session
|
||||
from app.utils.security import get_secure_headers
|
||||
|
||||
|
||||
def create_app(test_config=None):
|
||||
"""Create and configure the Flask application using the factory pattern."""
|
||||
app = Flask(__name__, instance_relative_config=True)
|
||||
|
||||
# Load config
|
||||
if test_config is None:
|
||||
app.config.from_object("app.config.Config")
|
||||
else:
|
||||
app.config.from_mapping(test_config)
|
||||
|
||||
# Ensure instance folder exists
|
||||
try:
|
||||
os.makedirs(app.instance_path)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
# Initialize extensions
|
||||
db.init_app(app)
|
||||
migrate.init_app(app, db)
|
||||
login_manager.init_app(app)
|
||||
limiter.init_app(app)
|
||||
mail.init_app(app)
|
||||
session.init_app(app)
|
||||
|
||||
# Security headers
|
||||
if app.config.get("SECURE_HEADERS_ENABLED", False):
|
||||
Talisman(app, **get_secure_headers())
|
||||
|
||||
# CSRF protection
|
||||
csrf = SeaSurf(app)
|
||||
|
||||
# Register blueprints
|
||||
from app.auth import auth_bp
|
||||
app.register_blueprint(auth_bp)
|
||||
|
||||
from app.core import core_bp
|
||||
app.register_blueprint(core_bp)
|
||||
|
||||
from app.api import api_bp
|
||||
app.register_blueprint(api_bp)
|
||||
|
||||
# Error handlers
|
||||
from app.utils.error_handlers import register_error_handlers
|
||||
register_error_handlers(app)
|
||||
|
||||
# CLI commands
|
||||
from app.utils.commands import register_commands
|
||||
register_commands(app)
|
||||
|
||||
return app
|
Loading…
Add table
Add a link
Reference in a new issue