Skip to content

Commit f433efc

Browse files
authored
feat(ui-website): env-driven sibling URLs with localhost dev fallbacks (#42)
The UI website hardcoded `https://webjs.dev` and `https://docs.webjs.dev` as the defaults for its header + footer links. Local dev navigated off the localhost dev cluster as soon as you clicked the Webjs / Docs links, which broke the flow when working across all three apps simultaneously. Mirror the pattern the root website (`website/app/layout.ts`) already uses: - Flip the WEBSITE_URL / DOCS_URL defaults to the canonical localhost ports (`http://localhost:5000`, `http://localhost:4000`), matching each sibling app's `webjs:dev --port` flag. - Replace the one hardcoded `https://webjs.dev` link in the footer with the WEBSITE_URL constant (was a missed substitution). - Add `.env.example` documenting the same defaults so deployment env overrides have something to point at. - AGENTS.md table covering env var name, local fallback, production value, plus a note that copying .env.example is only needed when overriding (the fallbacks already match local). Deploys (ui.webjs.dev on Railway) MUST set WEBSITE_URL=https://webjs.dev and DOCS_URL=https://docs.webjs.dev in service env vars; otherwise the header + footer will link to the localhost ports in production. Adding that step to the deployment runbook is part of this commit's intent (see the AGENTS.md table).
1 parent 11a746b commit f433efc

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Sibling-app URLs surfaced in the UI website's header + footer.
2+
# Copy this file to `.env` (`cp .env.example .env`) for local dev.
3+
# Canonical localhost dev ports (one source of truth alongside the
4+
# matching fallbacks in app/layout.ts). Deployments override these
5+
# with real public URLs (e.g. via Railway's service env vars).
6+
WEBSITE_URL=http://localhost:5000
7+
DOCS_URL=http://localhost:4000

packages/ui/packages/website/AGENTS.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ The `predev` hook runs `scripts/copy-registry.js` to populate
103103
something to import. Re-running `npm run dev` re-populates from the
104104
current registry state.
105105

106+
### Sibling-app URLs (header, footer)
107+
108+
Sibling-app links in the header + footer (Webjs site, Docs) read from
109+
`WEBSITE_URL` / `DOCS_URL` env vars. Fallbacks are the canonical
110+
localhost dev ports so local `npm run dev` works with zero setup. Deploy
111+
by overriding via the service env (e.g. Railway's variables):
112+
113+
| Env var | Local fallback | Production value |
114+
|---|---|---|
115+
| `WEBSITE_URL` | `http://localhost:5000` | `https://webjs.dev` |
116+
| `DOCS_URL` | `http://localhost:4000` | `https://docs.webjs.dev` |
117+
118+
`.env.example` in this directory documents the same defaults. Copy it to
119+
`.env` only if you need to override locally; the fallbacks already match.
120+
106121
---
107122

108123
Framework-wide rules and the framework API reference:

packages/ui/packages/website/app/layout.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
import { html } from '@webjskit/core';
22
import './_components/theme-toggle.ts';
33

4+
/**
5+
* Sibling-app URLs are read from env so the same code works in
6+
* `webjs dev` (localhost) and in deployment (real hosts). Fallbacks
7+
* are the canonical localhost dev ports (matching the matching apps'
8+
* `webjs:dev --port` flags). Deploy by overriding WEBSITE_URL /
9+
* DOCS_URL in the service env (Railway, etc.); `.env.example` in
10+
* this directory documents the same defaults for visibility.
11+
*
12+
* Guarded against `process` being undefined: this file also loads
13+
* on the client during hydration.
14+
*/
415
const env = (globalThis as any).process?.env ?? {};
5-
const WEBSITE_URL = env.WEBSITE_URL || 'https://webjs.dev';
6-
const DOCS_URL = env.DOCS_URL || 'https://docs.webjs.dev';
16+
const WEBSITE_URL = env.WEBSITE_URL || 'http://localhost:5000';
17+
const DOCS_URL = env.DOCS_URL || 'http://localhost:4000';
718

819
const TITLE = 'Webjs UI: AI-first component library';
920
const DESCRIPTION =
@@ -310,7 +321,7 @@ export default function Layout({ children }: { children: any }) {
310321
311322
<footer class="border-t mt-20 py-8 text-center" style="color: var(--fg-subtle); font-size: 13px">
312323
<div class="max-w-5xl mx-auto px-6">
313-
<a class="text-brand no-underline hover:underline" href="https://webjs.dev" target="_blank">Webjs</a> ·
324+
<a class="text-brand no-underline hover:underline" href=${WEBSITE_URL} target="_blank">Webjs</a> ·
314325
<a class="text-brand no-underline hover:underline" href=${DOCS_URL} target="_blank">Docs</a> ·
315326
<a class="text-brand no-underline hover:underline" href="https://github.com/vivek7405/webjs" target="_blank">GitHub</a>
316327
</div>

0 commit comments

Comments
 (0)