23 lines
812 B
TypeScript
23 lines
812 B
TypeScript
// The frontend->backend address is deliberately NOT a backend-stored setting
|
|
// (see project-structure.md "Frontend → backend address"). It's read here from:
|
|
// 1. a deploy-time env var (VITE_BACKEND_URL), or
|
|
// 2. a value saved in the browser via the connection setup screen, or
|
|
// 3. a localhost fallback for local dev against the mock backend.
|
|
|
|
const STORAGE_KEY = 'homefeed:backendUrl';
|
|
const DEFAULT_URL = 'http://localhost:4000';
|
|
|
|
export function getBackendUrl(): string {
|
|
if (typeof localStorage !== 'undefined') {
|
|
const stored = localStorage.getItem(STORAGE_KEY);
|
|
if (stored) return stored;
|
|
}
|
|
return import.meta.env.VITE_BACKEND_URL || DEFAULT_URL;
|
|
}
|
|
|
|
export function setBackendUrl(url: string) {
|
|
if (typeof localStorage !== 'undefined') {
|
|
localStorage.setItem(STORAGE_KEY, url);
|
|
}
|
|
}
|