From 478d3a74897c3e42ca95e460d832aeadb5046f46 Mon Sep 17 00:00:00 2001 From: Nils Pukropp Date: Mon, 16 Feb 2026 17:33:27 +0100 Subject: [PATCH] fixed backend routing --- backend/holy_backend/urls.py | 7 +++---- docker-compose.yml | 10 ++++------ frontend/src/App.tsx | 9 ++++----- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/backend/holy_backend/urls.py b/backend/holy_backend/urls.py index bb72800..a21f7b1 100644 --- a/backend/holy_backend/urls.py +++ b/backend/holy_backend/urls.py @@ -4,15 +4,14 @@ from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, Spec from rest_framework.authtoken.views import obtain_auth_token from django.conf import settings from django.conf.urls.static import static - from django.views.static import serve -import re import os -admin_path = os.environ.get('ADMIN_URL', 'admin/') +# Ensure the admin path is clean and always ends with a slash for Django +admin_url = os.environ.get('ADMIN_URL', 'admin').strip('/') urlpatterns = [ - path(admin_path, admin.site.urls), + path(f'{admin_url}/', admin.site.urls), path('api/', include('api.urls')), path('api/token/', obtain_auth_token, name='api_token'), path('api-auth/', include('rest_framework.urls')), diff --git a/docker-compose.yml b/docker-compose.yml index 5e66a0c..d939e66 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,9 +20,9 @@ services: labels: - "traefik.enable=true" - "traefik.docker.network=narl" - # Higher priority for specific backend paths + # Explicitly capture specific paths for the backend - "traefik.http.routers.holy-backend.priority=20" - - "traefik.http.routers.holy-backend.rule=Host(`holy.narl.io`) && (PathPrefix(`/api`) || PathPrefix(`/admin`) || PathPrefix(`/static`) || PathPrefix(`/media`))" + - "traefik.http.routers.holy-backend.rule=Host(`holy.narl.io`) && (PathPrefix(`/api`)||PathPrefix(`/admin`)||PathPrefix(`/static`)||PathPrefix(`/media`))" - "traefik.http.routers.holy-backend.entrypoints=websecure" - "traefik.http.routers.holy-backend.tls.certresolver=https_resolver" - "traefik.http.services.holy-backend.loadbalancer.server.port=8000" @@ -32,21 +32,19 @@ services: build: context: ./frontend args: - # Bake the API URL into the production build - VITE_API_URL=https://holy.narl.io/api/ container_name: holy-frontend restart: unless-stopped networks: - narl - # In production, we don't mount volumes for code to ensure container integrity depends_on: - backend labels: - "traefik.enable=true" - "traefik.docker.network=narl" - # Lower priority acts as catch-all for the domain + # Frontend ONLY matches if it's NOT a backend path - "traefik.http.routers.holy-frontend.priority=10" - - "traefik.http.routers.holy-frontend.rule=Host(`holy.narl.io`)" + - "traefik.http.routers.holy-frontend.rule=Host(`holy.narl.io`) && ! (PathPrefix(`/api`)||PathPrefix(`/admin`)||PathPrefix(`/static`)||PathPrefix(`/media`))" - "traefik.http.routers.holy-frontend.entrypoints=websecure" - "traefik.http.routers.holy-frontend.tls.certresolver=https_resolver" - "traefik.http.services.holy-frontend.loadbalancer.server.port=80" diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index e0d2976..57503f8 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -32,7 +32,7 @@ import ExpandMore from '@mui/icons-material/ExpandMore'; import { getTheme, type CatppuccinTheme } from './theme'; import api from './api'; -// Lazy load components for production performance +// Code splitting const CategoryList = lazy(() => import('./pages/CategoryList')); const CategoryFlavors = lazy(() => import('./pages/categories/CategoryFlavors')); const FlavorDetail = lazy(() => import('./pages/flavors/FlavorDetail')); @@ -87,7 +87,7 @@ const GlobalSearch = () => { freeSolo size="small" options={options} - getOptionLabel={(option) => typeof option === 'string' ? option : option.name} + getOptionLabel={(option) => typeof option === 'string' ? option : (option.name || '')} inputValue={query} onInputChange={(_, newValue) => setQuery(typeof newValue === 'string' ? newValue : '')} onChange={(_, newValue) => { @@ -204,7 +204,7 @@ const App: React.FC = () => { - {user?.username && !user.avatar && user.username.charAt(0).toUpperCase()} + {user?.username ? user.username.charAt(0).toUpperCase() : '?'} setDrawerOpen(false)} style={{ color: 'inherit', textDecoration: 'none' }}>Holy Flavors @@ -326,7 +326,7 @@ const App: React.FC = () => { setAnchorEl(e.currentTarget)} sx={{ ml: 1 }}> - {user.username && !user.avatar && user.username.charAt(0).toUpperCase()} + {user.username ? user.username.charAt(0).toUpperCase() : '?'} { } /> } /> } /> - {/* Fallback route for unknown paths */} 404 - Page Not Found} />