Skip to content

Commit b555ec6

Browse files
committed
feat: Serve UI files
1 parent c1b2919 commit b555ec6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

splinter/settings/static.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626

2727
def configure_static(settings):
28+
settings['UI_ROOT'] = os.path.join(settings['BASE_DIR'], 'ui')
2829
settings['STATIC_ROOT'] = os.path.join(settings['BASE_DIR'], 'static')
2930
settings['MEDIA_ROOT'] = os.path.join(settings['BASE_DIR'], 'media')
3031

splinter/urls.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
import os.path
2+
3+
from django.conf import settings
14
from django.urls import include, path
5+
from django.views.static import serve
26

37
from splinter.core.views import APIErrorView
48

9+
10+
def serve_ui(request, path):
11+
path = os.path.normpath(path).lstrip('/')
12+
if os.path.isdir(os.path.join(settings.UI_ROOT, path)):
13+
path = os.path.join(path, 'index.html')
14+
15+
return serve(request, path, document_root=settings.UI_ROOT)
16+
17+
518
urlpatterns = [
619
path('', include('splinter.core.health.urls')),
720
path('', include('splinter.core.openapi.urls', namespace='openapi')),
@@ -15,5 +28,11 @@
1528
path('api/', include('splinter.apps.user.urls')),
1629
]
1730

31+
if not settings.DEBUG:
32+
urlpatterns.extend([
33+
path('', serve_ui, {'path': ''}),
34+
path('<path:path>', serve_ui),
35+
])
36+
1837
handler404 = APIErrorView.as_view(status=404)
1938
handler500 = APIErrorView.as_view(status=500)

0 commit comments

Comments
 (0)