summaryrefslogtreecommitdiff
path: root/src/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/__init__.py')
-rw-r--r--src/__init__.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/__init__.py b/src/__init__.py
new file mode 100644
index 0000000..f6ad74a
--- /dev/null
+++ b/src/__init__.py
@@ -0,0 +1,42 @@
+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.debug = app.config["STAGE"] == "debug"
+app.permanent_session_lifetime = admin.MAX_LOGIN_TIME
+
+app.register_blueprint(blog.blueprint)
+app.register_blueprint(website.blueprint)
+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()