Feat: allow hosting alby hub on subpath (#1439)

* feat: add base path to front end

- add docker build arg to set base path frontend is served under
- set vite.config.ts base value based on docker build arg
- update http variant request function to inject base path during calls to /api and /images
- update how static assets are loaded from public folder to inject base path during vite build

To use a base path build the docker image with --build-arg BASE_PATH=/hub/.
All assets and api calls from the frontend will use that base path as prefix.

The backend service is not using the base path, when using a proxy the base path has to be stripped.

* chore: simplify base path usage and add extra documentation

* chore: add extra documentation

---------

Co-authored-by: 8de2fdb0 <89734465+8de2fdb0@users.noreply.github.com>
This commit is contained in:
Roland 2025-06-26 17:53:40 +07:00 committed by GitHub
parent bce8b2103a
commit 51ce7c64a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 103 additions and 33 deletions

View file

@ -1,6 +1,12 @@
FROM node:20-alpine as frontend
# Set the base path for the frontend build
# This can be overridden at build time with --build-arg BASE_PATH=<url> e.g. --build-arg BASE_PATH=/hub
# Allows to build a frontend that can be served from a subpath, e.g. /hub
ARG BASE_PATH
WORKDIR /build
COPY frontend ./frontend
RUN echo "Building frontend with base path $BASE_PATH"
RUN cd frontend && yarn install --network-timeout 3000000 && yarn build:http
FROM golang:1.24 as builder

View file

@ -61,6 +61,14 @@ Go to `/frontend`
1. `yarn install`
2. `yarn dev`
### HTTP Production build
$ yarn build:http
If you plan to run Alby Hub on a subpath behind a reverse proxy, you can do:
$ BASE_PATH="/hub" yarn build:http
### Wails (Backend + Frontend)
_Make sure to have [wails](https://wails.io/docs/gettingstarted/installation) installed and all platform-specific dependencies installed (see wails doctor)_

View file

@ -4,6 +4,12 @@ import { ErrorResponse } from "src/types";
export const request = async <T>(
...args: Parameters<typeof fetch>
): Promise<T | undefined> => {
if (import.meta.env.BASE_URL !== "/") {
// if running on a subpath, include the subpath in the request URL
// BASE_URL is set via process.env.BASE_PATH, see https://vite.dev/guide/build#public-base-path
args[0] = import.meta.env.BASE_URL + args[0];
}
const token = getAuthToken();
if (token) {
if (!args[1]) {

View file

@ -13,7 +13,12 @@ import routes from "src/routes.tsx";
import { isHttpMode } from "src/utils/isHttpMode";
const createRouterFunc = isHttpMode() ? createBrowserRouter : createHashRouter;
const router = createRouterFunc(routes);
const router = createRouterFunc(routes, {
// if running on a subpath, use the subpath as the router basename
// BASE_URL is set via process.env.BASE_PATH, see https://vite.dev/guide/build#public-base-path
basename:
import.meta.env.BASE_URL !== "/" ? import.meta.env.BASE_URL : undefined,
});
function App() {
const { data: info } = useInfo();

View file

@ -46,6 +46,9 @@ import { useAlbyMe } from "src/hooks/useAlbyMe";
import { LinkStatus, useLinkAccount } from "src/hooks/useLinkAccount";
import { App, BudgetRenewalType } from "src/types";
import AlbyAccountDarkSVG from "public/images/illustrations/alby-account-dark.svg";
import AlbyAccountLightSVG from "public/images/illustrations/alby-account-light.svg";
function AlbyConnectionCard({ connection }: { connection?: App }) {
const { data: albyMe } = useAlbyMe();
const { loading, linkStatus, loadingLinkStatus, linkAccount } =
@ -109,11 +112,11 @@ function AlbyConnectionCard({ connection }: { connection?: App }) {
every app you access through your Alby Account will
handle payments via the Hub.
<img
src="/images/illustrations/alby-account-dark.svg"
src={AlbyAccountDarkSVG}
className="w-full hidden dark:block"
/>
<img
src="/images/illustrations/alby-account-light.svg"
src={AlbyAccountLightSVG}
className="w-full dark:hidden"
/>
You can add a budget that will restrict how much can be

View file

@ -5,6 +5,15 @@ import { AlbyHubLogo } from "src/components/icons/AlbyHubLogo";
import { Button } from "src/components/ui/button.tsx";
import { useInfo } from "src/hooks/useInfo";
import AntonopoulosSVG from "public/images/quotes/antonopoulos.svg";
import BackSVG from "public/images/quotes/back.svg";
import FinneySVG from "public/images/quotes/finney.svg";
import HayekSVG from "public/images/quotes/hayek.svg";
import NakamotoSVG from "public/images/quotes/nakamoto.svg";
import ObamaSVG from "public/images/quotes/obama.svg";
import RolandSVG from "public/images/quotes/roland.svg";
import WilsonSVG from "public/images/quotes/wilson.svg";
const quotes = [
{
content: `This isn't about nation-states anymore. This isn't about who adopts
@ -13,42 +22,42 @@ const quotes = [
largest economy. It is the first transnational economy, and it needs a
transnational currency.`,
author: "Andreas M. Antonopoulos",
imageUrl: "/images/quotes/antonopoulos.svg",
imageUrl: AntonopoulosSVG,
},
{
content: `It might make sense just to get some in case it catches on. If enough people think the same way, that becomes a self fulfilling prophecy. Once it gets bootstrapped, there are so many applications if you could effortlessly pay a few cents to a website as easily as dropping coins in a vending machine.`,
author: "Satoshi Nakamoto",
imageUrl: "/images/quotes/nakamoto.svg",
imageUrl: NakamotoSVG,
},
{
content: `Since we're all rich with bitcoins, or we will be once they're worth a million dollars like everyone expects, we ought to put some of this unearned wealth to good use.`,
author: "Hal Finney",
imageUrl: "/images/quotes/finney.svg",
imageUrl: FinneySVG,
},
{
content: `I don't believe we shall ever have a good money again before we take the thing out of the hands of government, that is, we can't take it violently out of the hands of government, all we can do is by some sly roundabout way introduce something that they can't stop.`,
author: "Friedrich August von Hayek",
imageUrl: "/images/quotes/hayek.svg",
imageUrl: HayekSVG,
},
{
content: `Bitcoin is what they fear it is.`,
author: "Cody Wilson",
imageUrl: "/images/quotes/wilson.svg",
imageUrl: WilsonSVG,
},
{
content: `If in fact you can't crack that at all, government can't get in then —everybody's walking around with a Swiss bank account in their pocket.`,
author: "Barack Obama",
imageUrl: "/images/quotes/obama.svg",
imageUrl: ObamaSVG,
},
{
content: `Bitcoin is the new wonder of the world, more work and human ingenuity, than went into the great pyramids of Egypt. The biggest computation ever done, a digital monument, a verifiable artefact of digital gold - the foundation of a new digital age.`,
author: "Adam Back",
imageUrl: "/images/quotes/back.svg",
imageUrl: BackSVG,
},
{
content: `We who choose Bitcoin, are pioneers of a new world. A world filled with freedom, hope and peace.`,
author: "Roland",
imageUrl: "/images/quotes/roland.svg",
imageUrl: RolandSVG,
},
];

View file

@ -44,6 +44,9 @@ import {
RecommendedChannelPeer,
} from "src/types";
import LightningNetworkDarkSVG from "public/images/illustrations/lightning-network-dark.svg";
import LightningNetworkLightSVG from "public/images/illustrations/lightning-network-light.svg";
function getPeerKey(peer: RecommendedChannelPeer) {
return JSON.stringify(peer);
}
@ -230,13 +233,10 @@ function NewChannelInternal({
/>
<div className="md:max-w-md max-w-full flex flex-col gap-5 flex-1">
<img
src="/images/illustrations/lightning-network-dark.svg"
src={LightningNetworkDarkSVG}
className="w-full hidden dark:block"
/>
<img
src="/images/illustrations/lightning-network-light.svg"
className="w-full dark:hidden"
/>
<img src={LightningNetworkLightSVG} className="w-full dark:hidden" />
<p className="text-muted-foreground">
Alby Hub works with selected service providers (LSPs) which provide
the best network connectivity and liquidity to receive payments.{" "}

View file

@ -48,6 +48,9 @@ import {
} from "src/types";
import { request } from "src/utils/request";
import LightningNetworkDarkSVG from "public/images/illustrations/lightning-network-dark.svg";
import LightningNetworkLightSVG from "public/images/illustrations/lightning-network-light.svg";
function getPeerKey(peer: RecommendedChannelPeer) {
return JSON.stringify(peer);
}
@ -209,13 +212,10 @@ function NewChannelInternal({
/>
<div className="md:max-w-md max-w-full flex flex-col gap-5 flex-1">
<img
src="/images/illustrations/lightning-network-dark.svg"
src={LightningNetworkDarkSVG}
className="w-full hidden dark:block"
/>
<img
src="/images/illustrations/lightning-network-light.svg"
className="w-full dark:hidden"
/>
<img src={LightningNetworkLightSVG} className="w-full dark:hidden" />
<p className="text-muted-foreground">
Open a channel with on-chain funds. Both parties are free to close the
channel at any time. However, by keeping more funds on your side of

View file

@ -20,6 +20,9 @@ import { MempoolAlert } from "src/components/MempoolAlert";
import { PayLightningInvoice } from "src/components/PayLightningInvoice";
import { ChannelPublicPrivateAlert } from "src/components/channels/ChannelPublicPrivateAlert";
import LightningNetworkDarkSVG from "public/images/illustrations/lightning-network-dark.svg";
import LightningNetworkLightSVG from "public/images/illustrations/lightning-network-light.svg";
export function AutoChannel() {
const { data: info } = useInfo();
const { data: channels } = useChannels(true);
@ -134,11 +137,11 @@ export function AutoChannel() {
<>
<div className="flex flex-col gap-6 max-w-md text-muted-foreground">
<img
src="/images/illustrations/lightning-network-dark.svg"
src={LightningNetworkDarkSVG}
className="w-full hidden dark:block"
/>
<img
src="/images/illustrations/lightning-network-light.svg"
src={LightningNetworkLightSVG}
className="w-full dark:hidden"
/>

View file

@ -23,6 +23,9 @@ import { PayLightningInvoice } from "src/components/PayLightningInvoice";
import { Table, TableBody, TableCell, TableRow } from "src/components/ui/table";
import { ALBY_MIN_HOSTED_BALANCE_FOR_FIRST_CHANNEL } from "src/constants";
import LightningNetworkDarkSVG from "public/images/illustrations/lightning-network-dark.svg";
import LightningNetworkLightSVG from "public/images/illustrations/lightning-network-light.svg";
export function FirstChannel() {
const { data: info } = useInfo();
const { data: channels } = useChannels(true);
@ -167,11 +170,11 @@ export function FirstChannel() {
<>
<div className="flex flex-col gap-6 max-w-md text-muted-foreground">
<img
src="/images/illustrations/lightning-network-dark.svg"
src={LightningNetworkDarkSVG}
className="w-full hidden dark:block"
/>
<img
src="/images/illustrations/lightning-network-light.svg"
src={LightningNetworkLightSVG}
className="w-full dark:hidden"
/>
{canPayForFirstChannel ? (

View file

@ -11,6 +11,9 @@ import ExternalLink from "src/components/ExternalLink";
import ResponsiveButton from "src/components/ResponsiveButton";
import { Button } from "src/components/ui/button";
import SubWalletDarkSVG from "public/images/illustrations/sub-wallet-dark.svg";
import SubWalletLightSVG from "public/images/illustrations/sub-wallet-light.svg";
export function SubwalletIntro() {
return (
<div className="grid gap-4">
@ -33,14 +36,8 @@ export function SubwalletIntro() {
<div>
<div className="flex flex-col gap-6 max-w-screen-md">
<div className="mb-2">
<img
src="/images/illustrations/sub-wallet-dark.svg"
className="w-72 hidden dark:block"
/>
<img
src="/images/illustrations/sub-wallet-light.svg"
className="w-72 dark:hidden"
/>
<img src={SubWalletDarkSVG} className="w-72 hidden dark:block" />
<img src={SubWalletLightSVG} className="w-72 dark:hidden" />
</div>
<div>
<div className="flex flex-row gap-3">

View file

@ -64,6 +64,10 @@ export default defineConfig(({ command }) => ({
alias: {
src: path.resolve(__dirname, "./src"),
wailsjs: path.resolve(__dirname, "./wailsjs"),
// used to refrence public assets when importing images or other
// assets from the public folder
// this is necessary to inject the base path during build
public: "",
},
},
build: {
@ -75,6 +79,7 @@ export default defineConfig(({ command }) => ({
cspNonce: "DEVELOPMENT",
}
: undefined,
base: process.env.BASE_PATH || "/",
}));
const DEVELOPMENT_NONCE = "'nonce-DEVELOPMENT'";

View file

@ -0,0 +1,8 @@
# FOR TESTING ONLY, do not use internal tls!
https://your-domain.com {
redir /example-path /example-path/ 301
handle_path /example-path* {
reverse_proxy localhost:8080
}
tls internal
}

View file

@ -0,0 +1,17 @@
# Caddy Subpath
This is an example of how to run Alby Hub on a subpath using Caddy
To test locally edit `sudo nano /etc/hosts` and add `127.0.0.1 your-domain.com`
Use the following environment variables when building the frontend:
```bash
BASE_PATH="/example-path" yarn build:http
```
Then run Alby Hub as normal. (if default port is not 8080 you will need to update the Caddyfile)
Then start caddy: `sudo caddy run -c ./Caddyfile`
and visit `http://your-domain.com/example-path