Skip to content

Add optional BASE_PREFIX to serve the site under a sub-directory#630

Merged
DeviaVir merged 2 commits into
Blockstream:masterfrom
DeviaVir:chase/base-prefix-subpath-deploys
Jun 22, 2026
Merged

Add optional BASE_PREFIX to serve the site under a sub-directory#630
DeviaVir merged 2 commits into
Blockstream:masterfrom
DeviaVir:chase/base-prefix-subpath-deploys

Conversation

@DeviaVir

Copy link
Copy Markdown
Contributor

What

Adds an optional BASE_PREFIX build option so the whole multi-network site can be served from a sub-directory instead of the domain root.

Setting BASE_PREFIX=preview produces a build served at:

  • /preview/ (bitcoin mainnet)
  • /preview/signet/, /preview/testnet/, ...
  • /preview/liquid/, /preview/liquidtestnet/, ...

This is useful for hosting more than one build of the explorer side by side under a single host (e.g. a long-lived branch/preview build alongside the main one).

How it works

  • build.sh applies BASE_PREFIX after each flavor's config.env resolves its per-network BASE_HREF, so the network sub-paths are preserved (/signet//preview/signet/).
  • API_URL is resolved before the prefix is applied and is left un-prefixed, so a prefixed build keeps talking to the same API backend rather than expecting a prefixed API.
  • The few cross-network links that are absolute (the network switcher in network-selection.js / nav-toggle.js, and the Explorer API tab in navbar.js) are routed through the prefix so they stay within the current deployment root instead of jumping back to /.

Compatibility

BASE_PREFIX is optional and defaults to empty. With no prefix set the build output and all links are unchanged.

Notes

prerender-server is not covered by this change.

Introduce a BASE_PREFIX build option that prepends a path segment to each
flavor's BASE_HREF, so the whole multi-network site can be served from a
sub-directory (e.g. BASE_PREFIX=preview -> /preview/, /preview/signet/,
/preview/liquid/, ...) instead of the domain root.

The prefix is applied after the flavor config resolves its per-network
BASE_HREF, so the network paths are preserved. API_URL is resolved before
the prefix is applied and is left un-prefixed, so a prefixed build keeps
talking to the same API backend.

Cross-network links that are absolute (the network switcher and the
Explorer API tab) are routed through the prefix so they stay within the
current deployment root. With no BASE_PREFIX set the output is unchanged.
@DeviaVir DeviaVir self-assigned this Jun 22, 2026
@DeviaVir DeviaVir marked this pull request as ready for review June 22, 2026 17:21
@DeviaVir DeviaVir requested review from Randy808 and Copilot and removed request for Randy808 June 22, 2026 17:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an optional BASE_PREFIX build option to allow deploying the multi-network Esplora UI under a sub-directory (e.g. /preview/...) while keeping API requests un-prefixed so the UI can still target the same backend paths.

Changes:

  • Add BASE_PREFIX support in build.sh by prefixing each flavor’s resolved BASE_HREF (but leaving API_URL unchanged).
  • Update cross-network UI links (network switcher, nav toggle) to respect the deployment root prefix.
  • Document the new BASE_PREFIX option in README.md.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
README.md Documents the new BASE_PREFIX build option and intended behavior.
build.sh Applies BASE_PREFIX after flavor config resolves BASE_HREF, keeping API_URL un-prefixed.
client/src/views/network-selection.js Prefixes cross-network menu links with the deployment root.
client/src/views/nav-toggle.js Prefixes hardcoded cross-network explorer links with the deployment root.
client/src/views/navbar.js Updates the “Explorer API” nav link to incorporate the deployment root prefix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread build.sh
Comment thread client/src/views/navbar.js Outdated
Randy808
Randy808 previously approved these changes Jun 22, 2026
The Explorer API link was the only absolute navbar link (/explorer-api).
The router strips the full BASE_HREF before matching route('/explorer-api'),
so under a sub-directory or non-root network the absolute path never
matches. Use a relative href, consistent with the Dashboard/Blocks/
Transactions links, so it resolves against BASE_HREF and stays within the
current network and deployment root.
@DeviaVir DeviaVir merged commit 9a2c326 into Blockstream:master Jun 22, 2026
3 checks passed
@DeviaVir DeviaVir deleted the chase/base-prefix-subpath-deploys branch June 22, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants