Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand Down
11 changes: 7 additions & 4 deletions client/src/views/nav-toggle.js
Original file line number Diff line number Diff line change
@@ -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 () =>
Expand Down Expand Up @@ -40,10 +43,10 @@ export default () =>
<div className="link-list">
<h4 className="menu-title font-h5">Explorers</h4>
<ul className="font-p3">
<li><a href="/" rel="external">Bitcoin</a></li>
<li><a href="/liquid/" rel="external">Liquid Network</a></li>
<li><a href="/testnet/" rel="external" target="_blank">Bitcoin Testnet</a></li>
<li><a href="/liquidtestnet/" rel="external" target="_blank">Liquid Testnet</a></li>
<li><a href={`${siteRoot}/`} rel="external">Bitcoin</a></li>
<li><a href={`${siteRoot}/liquid/`} rel="external">Liquid Network</a></li>
<li><a href={`${siteRoot}/testnet/`} rel="external" target="_blank">Bitcoin Testnet</a></li>
<li><a href={`${siteRoot}/liquidtestnet/`} rel="external" target="_blank">Liquid Testnet</a></li>
</ul>
<h4 className="menu-title font-h5">Developer Tools</h4>
<ul className="font-p3">
Expand Down
2 changes: 1 addition & 1 deletion client/src/views/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default S =>
<a href="blocks/recent" class={{ active: S.activeTab == 'recentBlocks' }}>Blocks</a>
<a href="tx/recent" class={{ active: S.activeTab == 'recentTxs' }}>Transactions</a>
{ process.env.IS_ELEMENTS ? <a href="assets" class={{ active: S.activeTab == 'assets' }}>Assets<sup className="highlight"></sup></a> : "" }
<a href="/explorer-api" class={{ active: S.activeTab == 'apiLanding' }}>Explorer API</a>
<a href="explorer-api" class={{ active: S.activeTab == 'apiLanding' }}>Explorer API</a>
</div>
{ menu(S) }
</nav>
Expand Down
6 changes: 5 additions & 1 deletion client/src/views/network-selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const items = process.env.MENU_ITEMS && JSON.parse(process.env.MENU_ITEMS),
active = process.env.MENU_ACTIVE;

const staticRoot = process.env.STATIC_ROOT || "";
// Keep cross-network links within the current deployment root when the site is served under a
// sub-directory (BASE_PREFIX). No-op for a root deployment (empty prefix).
const siteRoot = process.env.BASE_PREFIX || "";
const withRoot = (url) => (siteRoot && url && url.charAt(0) === "/" ? siteRoot + url : url);
const itemEntries = items ? Object.entries(items) : [];
const activeName = active || (itemEntries[0] && itemEntries[0][0]);
const activeId = activeName && activeName.replace(/ /g, "");
Expand Down Expand Up @@ -43,7 +47,7 @@ export default ({ t, page }) => (
return (
<a
id={name.replace(/ /g, "")}
href={url}
href={withRoot(url)}
className={`network-hover-menu-option-container ${name.replace(/ /g, "").toLowerCase()} ${name === activeName ? "active" : ""}`}
rel="external"
>
Expand Down