mirror of
https://github.com/zonemaster/zonemaster-gui.git
synced 2026-01-19 12:34:13 +01:00
In order to support use cases where the GUI is served from a non-root base URL (i.e. https://zonemaster.example/some/subdirectory instead of https://zonemaster.example), some modifications were necessary to some Astro and Svelte files in the project. I initially tried to keep my modifications to the Apache configuration files without touching anything else, but I quickly realized that it couldn’t be done by editing Apache configuration files alone. That is because the build process assumes that the site is served from a base directory of / and all HTML files have baked-in absolute URLs. Fortunately, astro.config.mjs allows setting a base path that can be easily referred to from Astro and Svelte files. Setting it fixed *almost* everything: CSS and JS assets load from the right place, but favicons did not and some link target URLs needed manual adjustment in order to include the base directory. I am not familiar with these technologies and there might be a better approach to some of the edits I’ve made to Astro and Svelte files. So instead of having to edit the Apache configuration file, one needs to edit that file and config.ts in order to set the base URL to a non-default value. This seems to me like an acceptable compromise.
55 lines
1.8 KiB
Text
55 lines
1.8 KiB
Text
<VirtualHost *:80>
|
|
|
|
# BASE_URL can be set and DEFAULT_LANGUAGE can be updated.
|
|
|
|
# Uncomment the following line *only* if the GUI is served from a
|
|
# subdirectory. The setting here must match the setting in config.ts.
|
|
# Must start with a slash, but not end with a slash.
|
|
# Define BASE_URL "/subdirectory" # Undefined by default
|
|
|
|
# Default language must be updated if "defaultLanguage" in config.ts is
|
|
# changed. Both must match.
|
|
Define DEFAULT_LANGUAGE "en"
|
|
|
|
|
|
# Nothing to set or update below. #
|
|
|
|
DirectoryIndex index.html
|
|
|
|
<IfDefine BASE_URL>
|
|
Alias ${BASE_URL} /var/www/html/zonemaster-web-gui/dist
|
|
Define API_BASE_URL "${BASE_URL}/api"
|
|
</IfDefine>
|
|
|
|
<IfDefine !BASE_URL>
|
|
DocumentRoot /var/www/html/zonemaster-web-gui/dist
|
|
Define API_BASE_URL "/api"
|
|
</IfDefine>
|
|
|
|
<Directory /var/www/html/zonemaster-web-gui/dist>
|
|
Options Indexes FollowSymLinks
|
|
AllowOverride None
|
|
Require all granted
|
|
|
|
RewriteEngine On
|
|
<IfDefine BASE_URL>
|
|
RewriteBase ${BASE_URL}/
|
|
</IfDefine>
|
|
|
|
# Rewrite /result/{anything} to {default_language}/result/id/index.html
|
|
RewriteCond %{REQUEST_FILENAME} !-f
|
|
RewriteCond %{REQUEST_FILENAME} !-d
|
|
RewriteRule ^result/[^/]+/?$ ${DEFAULT_LANGUAGE}/result/id/index.html [L]
|
|
|
|
# Rewrite /{lang}/result/{anything} to /{lang}/result/id/index.html
|
|
RewriteCond %{REQUEST_FILENAME} !-f
|
|
RewriteCond %{REQUEST_FILENAME} !-d
|
|
RewriteRule ^([^/]+)/result/[^/]+/?$ $1/result/id/index.html [L]
|
|
</Directory>
|
|
|
|
<Location "${API_BASE_URL}">
|
|
ProxyPass http://localhost:5000/
|
|
ProxyPassReverse http://localhost:5000/
|
|
ProxyPreserveHost On
|
|
</Location>
|
|
</VirtualHost>
|