diff --git a/client/docker/Dockerfile b/client/docker/Dockerfile index 9924e6e9..0b351e35 100644 --- a/client/docker/Dockerfile +++ b/client/docker/Dockerfile @@ -1,5 +1,7 @@ FROM ghcr.io/openconext/openconext-basecontainers/apache2:latest ADD ./dist/ /var/www/ RUN rm -rf /etc/apache2/sites-enabled/*.conf +# mod_substitute is used to rewrite root-relative links to /roles/ in responses +RUN a2enmod substitute COPY ./docker/appconf.conf /etc/apache2/sites-enabled/ diff --git a/client/docker/appconf.conf b/client/docker/appconf.conf index 543540e3..0dfec658 100644 --- a/client/docker/appconf.conf +++ b/client/docker/appconf.conf @@ -1,5 +1,10 @@ ServerName accessclient RewriteEngine On +# When served via the access dashboard the app lives under /roles/: +# strip the prefix internally and flag the request so root-relative +# links in the response can be rewritten back to /roles/ +RewriteRule ^/roles/?$ /index.html [E=ROLES_PREFIX:1,L] +RewriteRule ^/roles/(.*)$ /$1 [E=ROLES_PREFIX:1,L] RewriteCond %{REQUEST_URI} !\.(js|css)(\.map)?$ RewriteCond %{REQUEST_URI} !\.svg$ RewriteCond %{REQUEST_URI} !\.png$ @@ -61,3 +66,13 @@ Header set Expires "Sun, 8 Jun 1986 08:06:00 GMT" Header always set X-Frame-Options "DENY" Header always set Referrer-Policy "strict-origin-when-cross-origin" Header always set X-Content-Type-Options "nosniff" + +# Rewrite root-relative links in HTML responses when the app was +# requested under the /roles/ prefix (eg via the access dashboard) + + + Substitute "s|href=\"/|href=\"/roles/|i" + Substitute "s|src=\"/|src=\"/roles/|i" + Substitute "s|action=\"/|action=\"/roles/|i" + + diff --git a/client/vite.config.js b/client/vite.config.js index 0624b8f2..8742cae3 100644 --- a/client/vite.config.js +++ b/client/vite.config.js @@ -21,6 +21,8 @@ export default defineConfig({ globals: true }, build: { + // relative asset URLs so the app also works under a path prefix (eg /roles/) + base: './', chunkSizeWarningLimit: 1000 }, server: {