feat: rate limiting
Python Lint CI / ruff-format-check (push) Successful in 44s
Python Lint CI / ty (push) Successful in 44s
Python Lint CI / ruff (push) Successful in 44s

This commit is contained in:
2026-07-03 15:33:06 +02:00
parent 92d2e7c3a0
commit 59a6f49700
6 changed files with 151 additions and 7 deletions
+9
View File
@@ -2,6 +2,8 @@ import logging
import typing
import flask
import flask_limiter
import flask_limiter.util
import gunicorn.app.base
from app import PKG_NAME
@@ -22,12 +24,19 @@ class Server(gunicorn.app.base.BaseApplication):
self.app = flask.Flask(
PKG_NAME, static_folder="dist/assets", template_folder="dist"
)
self.limiter = flask_limiter.Limiter(
flask_limiter.util.get_remote_address,
app=self.app,
default_limits=["100 per minute"],
storage_uri=params.cache_uri,
)
self._index_content: str | None = None
self.logger: logging.Logger = logging.getLogger(self.__class__.__name__)
super().__init__()
def register_routes(self) -> typing.Self:
@self.app.route("/")
@self.limiter.exempt
def index() -> str:
return flask.render_template("index.html")