Skip to content

Commit

Permalink
feat: Serve UI files
Browse files Browse the repository at this point in the history
  • Loading branch information
uadnan committed Jan 7, 2025
1 parent d4232a5 commit b489fa2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions splinter/settings/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


def configure_static(settings):
settings['UI_ROOT'] = os.path.join(settings['BASE_DIR'], 'ui')
settings['STATIC_ROOT'] = os.path.join(settings['BASE_DIR'], 'static')
settings['MEDIA_ROOT'] = os.path.join(settings['BASE_DIR'], 'media')

Expand Down
19 changes: 19 additions & 0 deletions splinter/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import os.path

from django.conf import settings
from django.urls import include, path
from django.views.static import serve

from splinter.core.views import APIErrorView


def serve_ui(request, path):
path = os.path.normpath(path).lstrip('/')
if os.path.isdir(os.path.join(settings.UI_ROOT, path)):
path = os.path.join(path, 'index.html')

return serve(request, path, document_root=settings.UI_ROOT)


urlpatterns = [
path('', include('splinter.core.health.urls')),
path('', include('splinter.core.openapi.urls', namespace='openapi')),
Expand All @@ -15,5 +28,11 @@
path('api/', include('splinter.apps.user.urls')),
]

if not settings.DEBUG:
urlpatterns.extend([
path('', serve_ui, {'path': ''}),
path('<path:path>', serve_ui),
])

handler404 = APIErrorView.as_view(status=404)
handler500 = APIErrorView.as_view(status=500)

0 comments on commit b489fa2

Please sign in to comment.