Skip to content

Commit

Permalink
add debug toolbar to app middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
michael7nightingale committed Oct 19, 2023
1 parent f7cda6e commit 176de5f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ecdsa==0.18.0
email-validator==2.0.0.post2
fastapi==0.100.0
fastapi-authtools==0.6
fastapi-debug-toolbar==0.5.0
flake8==6.1.0
fonttools==4.42.0
frozenlist==1.4.0
Expand Down Expand Up @@ -61,6 +62,7 @@ pydantic-extra-types==2.0.0
pydantic-settings==2.0.2
pydantic_core==2.1.2
pyflakes==3.1.0
pyinstrument==4.6.0
pymongo==4.5.0
pyparsing==3.0.9
pypika-tortoise==0.1.6
Expand All @@ -77,6 +79,7 @@ requests==2.31.0
rsa==4.9
six==1.16.0
sniffio==1.3.0
sqlparse==0.4.4
starlette==0.27.0
sympy==1.12
tomlkit==0.12.1
Expand Down
7 changes: 6 additions & 1 deletion backend/src/core/middleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from fastapi import Request, Response, FastAPI
from starlette.middleware.cors import CORSMiddleware
from debug_toolbar.middleware import DebugToolbarMiddleware
import time

from starlette.middleware.cors import CORSMiddleware

middleware_stack = {}

Expand Down Expand Up @@ -31,6 +32,10 @@ def register_middleware(app: FastAPI) -> None:
app.middleware(type_)(func)

origins = ["*"]
app.add_middleware(
DebugToolbarMiddleware,
panels=["debug_toolbar.panels.tortoise.TortoisePanel"],
)
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
class Server:

def __init__(self):
self._app = FastAPI()
self._settings = get_app_settings()
self._app = FastAPI(debug=self.settings.DEBUG)

self._configurate_db()
self._configurate_app()
Expand Down
1 change: 1 addition & 0 deletions backend/src/core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class AppEnvTypes(StrEnum):


class BaseAppSettings(BaseSettings):
DEBUG: bool

SUPERUSER_USERNAME: str
SUPERUSER_PASSWORD: str
Expand Down
1 change: 1 addition & 0 deletions backend/src/core/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class DevAppSettings(BaseAppSettings):
DB_HOST: str
DB_PORT: str
DB_NAME: str
DEBUG: bool = True

@property
def db_uri(self) -> str:
Expand Down
2 changes: 2 additions & 0 deletions backend/src/core/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class ProdAppSettings(BaseAppSettings):
DB_PORT: str
DB_NAME: str

DEBUG: bool = False

@property
def db_uri(self) -> str:
host_address = self.DB_HOST
Expand Down
1 change: 1 addition & 0 deletions backend/src/core/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class TestAppSettings(BaseAppSettings):
DB_DRIVER: str
DB_NAME: str
DEBUG: bool = True

@property
def db_uri(self) -> str:
Expand Down

0 comments on commit 176de5f

Please sign in to comment.