Skip to content

Commit 0f2a3ff

Browse files
committed
Add misc
1 parent 85c9e6d commit 0f2a3ff

File tree

4 files changed

+91
-3
lines changed

4 files changed

+91
-3
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pytest-flask = "*"
3131
pytest = "*"
3232
pytest-asyncio = "*"
3333
beautifulsoup4 = "*"
34+
tox = "*"
3435

3536
[requires]
3637
python_version = "3.12"

Pipfile.lock

Lines changed: 73 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/controllers/HomeController.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import re, jsonpickle, logging
2-
from quart import Blueprint, render_template, session
2+
from quart import Blueprint, ResponseReturnValue, render_template, session
33
from datetime import datetime, timezone
44
from ..common.Authentication import Authentication
55
from ..models.UserModel import UserModel

src/main.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import quart_flask_patch
22
import logging, os, asyncio, json
3+
from datetime import date, datetime, timedelta, timezone
34
from urllib import parse
45
from hypercorn.config import Config
5-
from quart import Quart, request
6+
from hypercorn.middleware import HTTPToHTTPSRedirectMiddleware
7+
from quart import Quart, Response
68
from flask_healthz import Healthz, HealthError
79
from quart_wtf.csrf import CSRFProtect
810
from quart_cors import cors
@@ -20,15 +22,24 @@
2022
logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S')
2123
#oidc.init_app(app)
2224

25+
def _add_secure_headers(response: Response) -> Response:
26+
response.headers["Strict-Transport-Security"] = (
27+
"max-age=63072000; includeSubDomains; preload"
28+
)
29+
response.headers["X-Content-Type-Options"] = "nosniff"
30+
return response
31+
2332
def create_app() -> Quart:
2433
"""
2534
Create App
2635
"""
2736
# App initialization
2837
app = Quart(__name__, template_folder='view/templates', static_url_path='', static_folder='view/static')
2938
app.config.from_file("/etc/pythonrestapi_config.json", json.load)
39+
app.config["SEND_FILE_MAX_AGE_DEFAULT"] = timedelta(days=90)
3040
app.config["SQLALCHEMY_DATABASE_URI"] = f"postgresql+psycopg://{os.environ.get('DB_USERNAME')}:{parse.quote(os.environ.get('DB_PASSWORD'))}@{app.config['DB_HOST']}/library"
3141
app.config["POSTGRESQL_DATABASE_URI"] = f"postgresql://{os.environ.get('DB_USERNAME')}:{parse.quote(os.environ.get('DB_PASSWORD'))}@{app.config['DB_HOST']}/library"
42+
app.after_request(_add_secure_headers)
3243
app.register_blueprint(home_blueprint, url_prefix="/")
3344
app.register_blueprint(fibonacci_blueprint, url_prefix="/fibonacci")
3445
app.register_blueprint(auth_blueprint, url_prefix="/auth")
@@ -41,6 +52,10 @@ def create_app() -> Quart:
4152
csrf = CSRFProtect(app)
4253
bcrypt.init_app(app)
4354
db.init_app(app)
55+
if app.debug:
56+
return HTTPToHTTPSRedirectMiddleware(app, "khteh.com") # type: ignore - Defined in hypercorn.toml server_names
57+
else:
58+
app.config["TEMPLATES_AUTO_RELOAD"] = True
4459
return app
4560

4661
def liveness():

0 commit comments

Comments
 (0)