2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 04:25:42 +00:00

Static Asset Management (#9292)

* Caddyfile: Redirect asset requests

- Ensure the static asset files are served by the proxy
- Reduce gunicorn / python load
- Significant server performance increase

* Allow CORS requests to 'assets' path

* Update static assets path for vite build

* Remove RedirectAssetView

* Specify relative base path

Ref: https://vite.dev/guide/build.html#relative-base

* Revert settings.py

* Revert caddyfile

* Remove defunct unit test

* Add timeout to test
This commit is contained in:
Oliver
2025-03-14 08:20:51 +11:00
committed by GitHub
parent b25bf5e669
commit 3dfd1ed146
4 changed files with 3 additions and 21 deletions

View File

@ -84,8 +84,3 @@ class TemplateTagTest(InvenTreeTestCase):
rsp = get_frontend_settings(False)
self.assertNotIn('show_server_selector', rsp)
self.assertEqual(rsp['server_list'], ['aa', 'bb'])
def test_redirects(self):
"""Test the redirect helper."""
response = self.client.get('/assets/testpath')
self.assertEqual(response.url, '/static/web/assets/testpath')

View File

@ -1,31 +1,16 @@
"""URLs for web app."""
from django.conf import settings
from django.shortcuts import redirect
from django.urls import include, path, re_path
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic import TemplateView
class RedirectAssetView(TemplateView):
"""View to redirect to static asset."""
def get(self, request, *args, **kwargs):
"""Redirect to static asset."""
return redirect(
f'{settings.STATIC_URL}web/assets/{kwargs["path"]}', permanent=True
)
spa_view = ensure_csrf_cookie(TemplateView.as_view(template_name='web/index.html'))
assets_path = path('assets/<path:path>', RedirectAssetView.as_view(), name='web-assets')
urlpatterns = [
path(
f'{settings.FRONTEND_URL_BASE}/',
include([
assets_path,
path(
'set-password?uid=<uid>&token=<token>',
spa_view,
@ -34,6 +19,5 @@ urlpatterns = [
re_path('.*', spa_view, name='platform-wildcard'),
]),
),
assets_path,
path(settings.FRONTEND_URL_BASE, spa_view, name='platform'),
]