Beispiel #1
0
def get_app():
    global _app
    if not _app:
        _app = CustomApp(
            title="FastAPI backend template",
            version="0.0.4",
            description="",
            exception_handlers=None,
            middleware=(
                Middleware(PrometheusMiddleware),
                Middleware(
                    CORSMiddleware,
                    allow_origins=ORIGINS,
                    allow_credentials=True,
                    allow_methods=["*"],
                    allow_headers=["*"],
                ),
            ),
        )

        _app.include_router(service_route)
        _app.include_router(router)

        for _mount in MOUNTS:
            _app.mount(*_mount)

        if settings.SENTRY_DSN:
            sentry_sdk.init(dsn=settings.SENTRY_DSN)
            _app.add_middleware(SentryAsgiMiddleware)
        db.init_app(_app)

    return _app
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from asgi import app
from core import settings
from core.db import db

db.init_app(app)
config.set_main_option("sqlalchemy.url", str(settings.DB_DSN))
target_metadata = db

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
Beispiel #3
0
from flaskext.markdown import Markdown
from flask_assets import Environment, Bundle

route_modules = ["auth", "blog", "progress", "home", "calendar", "books"]
for module in route_modules:
    exec("from routes.%s import %s" % (module, module))

from core.config import *
from core.db import db
from core.tables import User

app = Flask(__name__)

app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://" + DB_USER + ":" + DB_PASSWORD + "@" + DB_HOST + "/" + DB

db.init_app(app)

Markdown(app)

login_manager = LoginManager()
login_manager.init_app(app)


@login_manager.user_loader
def load_user(userid):
    user = User.query.get(int(userid))
    if user:
        return user


app.debug = DEBUG
Beispiel #4
0
def get_app():
    app: FastAPI = FastAPI(middleware=middleware)
    db.init_app(app)
    init_routers(app)
    init_models(app)
    return app