diff --git a/README.md b/README.md index 8cb0aef3..d0c68f8b 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ All options are optional. - `NODE_ENV` - set to `production` to enable js minification, or to `development` to disable (defaults to `production`) - `BASE_HREF` - base href for user interface (defaults to `/`, change if not served from the root directory) +- `BASE_PREFIX` - optional path prefix prepended to each flavor's `BASE_HREF`, to serve the whole multi-network site under a sub-directory (e.g. `BASE_PREFIX=preview` serves `/preview/`, `/preview/signet/`, ...). `API_URL` is left un-prefixed so a prefixed build still uses the same backend - `STATIC_ROOT` - root for static assets (defaults to `BASE_HREF`, change to load static assets from a different server) - `API_URL` - URL for HTTP REST API (defaults to `/api`, change if the API is available elsewhere) - `CANONICAL_URL` - absolute base url for user interface (optional, only required for opensearch and canonical link tags) diff --git a/build.sh b/build.sh index c3c22023..a557cdb4 100755 --- a/build.sh +++ b/build.sh @@ -9,6 +9,16 @@ export NODE_ENV=${NODE_ENV:=production} export BASE_HREF=${BASE_HREF:-/} export API_URL=${API_URL:-"${BASE_HREF}api"} +# Optional path prefix for serving the whole site under a sub-directory (e.g. a preview +# deploy keyed by branch name). Applied *after* the flavor sets its per-network BASE_HREF, +# so the network paths are preserved: / -> /$BASE_PREFIX/, /signet/ -> /$BASE_PREFIX/signet/. +# API_URL is resolved above, before this, so it keeps pointing at the un-prefixed network +# API and a prefixed build still talks to the same backend. +if [ -n "$BASE_PREFIX" ]; then + export BASE_HREF="/${BASE_PREFIX#/}${BASE_HREF}" + export BASE_PREFIX="/${BASE_PREFIX#/}" +fi + mkdir -p $DEST rm -rf $DEST/* diff --git a/client/src/views/nav-toggle.js b/client/src/views/nav-toggle.js index 7bd11b25..bf0f93ac 100644 --- a/client/src/views/nav-toggle.js +++ b/client/src/views/nav-toggle.js @@ -1,6 +1,9 @@ import { nativeAssetId } from '../const' const staticRoot = process.env.STATIC_ROOT || '' +// Prefix for cross-network links so they stay within the current deployment root when the +// whole site is served under a sub-directory (BASE_PREFIX). Empty for a root deployment. +const siteRoot = process.env.BASE_PREFIX || '' const hasCam = process.browser && navigator.mediaDevices && navigator.mediaDevices.getUserMedia export default () => @@ -40,10 +43,10 @@ export default () =>