blob: 9e66fc8e341aa8abf1156b047f907d4fb1be7b4a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
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()
|