TanStackT
TanStack9mo ago
9 replies
managerial-maroon

Start app with a dynamic base path

Hi everyone! I've been stuck on this issue for a while and could really use some guidance.
I'm trying to build my app with a Node target and make the same build work seamlessly with any base URL.

The base URL is defined by an environment variable (BASE_URL). Here are some examples of what I'm aiming for:
- If BASE_URL=/toto/, the app should run at example.com/toto.
- If BASE_URL=/foo/bar/, the app should run at example.com/foo/bar.
- If BASE_URL is unset, the app should run at example.com.

I've tested this on the latest versions from the main branches as well as the alpha branch with Devinxi, but I keep running into the same issues.

Here’s what I’ve tried so far:
- Setting NITRO_APP_BASE_URL, but it crashes the router.
- Using environment variables in
app.config.ts
(and
vite.config.ts
for the alpha branch), but it only work at build-time, not at runtime

Is there a best practice or a recommended approach I’m missing?

Any help would be greatly appreciated!
Was this page helpful?