src/dnsbl/api/__init__.py \
src/dnsbl/api/domains.py \
src/dnsbl/api/lists.py \
+ src/dnsbl/api/middlewares.py \
src/dnsbl/api/reports.py
pkgpython_apidir = $(pkgpythondir)/api
# Import the backend
from .. import Backend
+# Import middlewares
+from . import middlewares
+
# Initialize the app
app = fastapi.FastAPI(
title = "IPFire DNSBL API",
# Enable debug mode
debug = True,
)
+app.add_middleware(middlewares.DatabaseSessionMiddleware)
# Initialize the backend
backend = app.state.backend = Backend(
--- /dev/null
+###############################################################################
+# #
+# dnsbl - A DNS Blocklist Compositor For IPFire #
+# Copyright (C) 2026 IPFire Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+import fastapi
+
+class DatabaseSessionMiddleware(fastapi.applications.BaseHTTPMiddleware):
+ async def dispatch(self, request: fastapi.Request, call_next):
+ backend = request.app.state.backend
+
+ # Acquire a new database session and process the request
+ with backend.db.session() as session:
+ return await call_next(request)