Skip to content

Running qlever-ui behind Traefik #180

@tobiasschweizer

Description

@tobiasschweizer

Hi,

I am trying to run qlever-ui behind Traefik in a docker compose setup (got inspired by #99).

I have an issue when loading the JS files. Somehow, the app seems to serve HTML files instead of JS files, resulting in parsing errors such as:

Uncaught SyntaxError: Unexpected token '<' (at helper.js:1:1)
raphael.js:1 Uncaught SyntaxError: Unexpected token '<' (at raphael.js:1:1)
treant.js:1 Uncaught SyntaxError: Unexpected token '<' (at treant.js:1:1)
qleverUI.js:1 Uncaught SyntaxError: Unexpected token '<' (at qleverUI.js:1:1)
codemirror.js:1 Uncaught SyntaxError: Unexpected token '<' (at codemirror.js:1:1)
autocomplete.js:1 Uncaught SyntaxError: Unexpected token '<' (at autocomplete.js:1:1)
active-line.js:1 Uncaught SyntaxError: Unexpected token '<' (at active-line.js:1:1)
show-hint.js:1 Uncaught SyntaxError: Unexpected token '<' (at show-hint.js:1:1)
search.js:1 Uncaught SyntaxError: Unexpected token '<' (at search.js:1:1)
sparql.js:1 Uncaught SyntaxError: Unexpected token '<' (at sparql.js:1:1)
sparql-hint.js:1 Uncaught SyntaxError: Unexpected token '<' (at sparql-hint.js:1:1)
index.js:1 Failed to load module script: Expected a JavaScript-or-Wasm module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
keywordSearch.js:1 Uncaught SyntaxError: Unexpected token '<' (at keywordSearch.js:1:1)

I think this related to some settings regarding static files.
AI says that there is something wrong with https://github.com/qlever-dev/qlever-ui/blob/4e3d057b9214f4f2fec868532c6291bbb15ec78f/backend/urls.py and suggests to exclude static:

from django.urls import include, path, re_path
from rest_framework import routers
from rest_framework.generics import ListAPIView
from . import views

urlpatterns = [
    path(
        "api/backends/",
        views.BackendList.as_view(),
        name="backend-list",
    ),
    path(
        "api/backends/<slug:slug>/",
        views.BackendViewSet.as_view({"get": "retrieve"}),
        name="backend-detail",
    ),
    re_path(r"^api/share$", views.shareLink, name="shareLink"),
    re_path(
        r"^api/warmup/(?P<backend>[^/]+)/(?P<target>[a-zA-Z0-9_-]+)$",
        views.warmup,
        name="warmup",
    ),
    re_path(
        r"^api/examples/(?P<backend>[^/]+)$", views.examples, name="examples"
    ),
    re_path(
        r"^api/prefixes/(?P<backend>[^/]+)$", views.prefixes, name="prefixes"
    ),
    re_path(r"^api/config/(?P<backend>[^/]+)$", views.config, name="config"),
    
    # Catch-all for index - MUST BE LAST and exclude static/media/admin/api
    re_path(
        r"^(?!static/)(?!media/)(?!admin/)(?!api/)(?P<backend>[A-Za-z0-9\+@:()%\-_]*)(/(?P<short>[A-Za-z0-9]{6})?)?$",
        views.index,
        name="index",
    ),
]

The key change is adding (?!static/)(?!media/)(?!admin/)(?!api/) at the beginning, which are negative lookaheads that say "don't match if the path starts with static/, media/, admin/, or api/".

I tried this but it did not solve the issue. Any hints? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions