import asyncpg import quart as q from dotenv import dotenv_values from . import admin, blog, website app = q.Quart(__name__) app.config.from_mapping(dotenv_values()) app.config["admin_enabled"] = app.config.get("ADMIN_ENABLED") == "true" app.debug = app.config["STAGE"] == "debug" app.permanent_session_lifetime = admin.MAX_LOGIN_TIME app.register_blueprint(blog.blueprint) app.register_blueprint(website.blueprint) if app.config["admin_enabled"]: app.register_blueprint(admin.blueprint) @app.while_serving async def db_lifespan(): app.pool = await asyncpg.create_pool(app.config["DATABASE"]) yield await app.pool.close() @app.before_request async def make_login_permanent(): q.session.permanent = True @app.errorhandler(404) async def not_found(error): return ( await q.render_template( "404.html", title="Not Found!", description="the page you were looking for couldn't be found. sorry...", ), 404, ) def run() -> None: app.run()