chore: enhance frontend configuration for backend integration
- Added environment variables for backend URLs in the Dockerfile to facilitate dynamic configuration. - Updated Next.js configuration to include rewrites for health and API endpoints, improving backend connectivity. - Modified settings page to handle backend URL locking and normalization, enhancing user experience and data integrity.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
export const LOCAL_DEFAULT_BACKEND_URL = "http://localhost:8000"
|
||||
|
||||
export type ConfiguredBackendUrl =
|
||||
| { kind: "local" }
|
||||
| { kind: "fixed"; url: string }
|
||||
| { kind: "same-origin" }
|
||||
|
||||
export function configuredBackendUrl(): ConfiguredBackendUrl {
|
||||
const raw = process.env.NEXT_PUBLIC_BACKEND_URL
|
||||
if (raw === undefined || raw === "local") return { kind: "local" }
|
||||
if (raw === "" || raw === "same-origin") return { kind: "same-origin" }
|
||||
return { kind: "fixed", url: raw.replace(/\/$/, "") }
|
||||
}
|
||||
|
||||
export function defaultDataSourceMode(): "mock" | "live" {
|
||||
return process.env.NEXT_PUBLIC_DEFAULT_DATA_SOURCE === "live" ? "live" : "mock"
|
||||
}
|
||||
|
||||
export function isBackendUrlLocked(): boolean {
|
||||
const cfg = configuredBackendUrl()
|
||||
return cfg.kind === "same-origin" || cfg.kind === "fixed"
|
||||
}
|
||||
|
||||
export function resolveStoredBackendUrl(stored: string | null): string {
|
||||
const cfg = configuredBackendUrl()
|
||||
if (cfg.kind === "fixed") return cfg.url
|
||||
if (cfg.kind === "same-origin" && typeof window !== "undefined") {
|
||||
return window.location.origin
|
||||
}
|
||||
const trimmed = stored?.trim().replace(/\/$/, "")
|
||||
return trimmed || LOCAL_DEFAULT_BACKEND_URL
|
||||
}
|
||||
Reference in New Issue
Block a user