Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKallekleiv committed Jan 7, 2025
1 parent a370cd3 commit 7d4e9be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backend_py/primary/primary/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def custom_generate_unique_id(route: APIRoute) -> str:
# Also redirects to /login endpoint for some select paths
unprotected_paths = ["/logged_in_user", "/alive", "/openapi.json"]
paths_redirected_to_login = ["/", "/alive_protected"]
app.add_middleware(BrowserCacheMiddleware)
app.add_middleware(
EnforceLoggedInMiddleware,
unprotected_paths=unprotected_paths,
Expand All @@ -113,7 +114,7 @@ def custom_generate_unique_id(route: APIRoute) -> str:

session_store = RedisStore(config.REDIS_USER_SESSION_URL, prefix="user-auth:")
app.add_middleware(SessionMiddleware, store=session_store)
app.add_middleware(BrowserCacheMiddleware)

app.add_middleware(ProxyHeadersMiddleware, trusted_hosts="*")

# This middleware instance measures execution time of the endpoints, including the cost of other middleware
Expand Down
4 changes: 4 additions & 0 deletions backend_py/primary/primary/middleware/browser_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@


def custom_browser_cache_time(max_age: int):
"""Override default cache time for a specific route."""

def decorator(func):
@wraps(func)
async def wrapper(*args, **kwargs):
Expand All @@ -21,6 +23,8 @@ async def wrapper(*args, **kwargs):


class BrowserCacheMiddleware(BaseHTTPMiddleware):
"""Set default cache time for all routes."""

async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response:
response = await call_next(request)

Expand Down

0 comments on commit 7d4e9be

Please sign in to comment.