Browse Source

feat(backend): configure Django to serve compiled React SPA from frontend/dist

master
PouyaKhajavi 2 days ago
parent
commit
b9fe9ae896
  1. 5
      backend/config/settings.py
  2. 2
      backend/config/urls.py
  3. 1
      frontend/vite.config.js

5
backend/config/settings.py

@ -68,7 +68,7 @@ ROOT_URLCONF = 'config.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [BASE_DIR.parent / 'frontend' / 'dist'],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
@ -129,6 +129,9 @@ USE_TZ = True
# https://docs.djangoproject.com/en/6.0/howto/static-files/ # https://docs.djangoproject.com/en/6.0/howto/static-files/
STATIC_URL = 'static/' STATIC_URL = 'static/'
STATICFILES_DIRS = [
BASE_DIR.parent / 'frontend' / 'dist',
]
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/6.0/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/6.0/ref/settings/#default-auto-field

2
backend/config/urls.py

@ -16,9 +16,11 @@ Including another URLconf
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path,include from django.urls import path,include
from django.views.generic import TemplateView
from core.views import HealthCheckView from core.views import HealthCheckView
urlpatterns = [ urlpatterns = [
path('', TemplateView.as_view(template_name='index.html'), name='dashboard'),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('api/health/', HealthCheckView.as_view(), name='health-check'), path('api/health/', HealthCheckView.as_view(), name='health-check'),
path('api/crawlers/', include('crawler.urls')), path('api/crawlers/', include('crawler.urls')),

1
frontend/vite.config.js

@ -8,6 +8,7 @@ export default defineConfig({
react(), react(),
tailwindcss(), tailwindcss(),
], ],
base: '/static/',
server: { server: {
proxy: { proxy: {
'/api': { '/api': {

Loading…
Cancel
Save