17 lines
764 B
TypeScript
17 lines
764 B
TypeScript
import { origin } from '@lumina/libs/env';
|
|
import * as v from 'valibot';
|
|
|
|
/**
|
|
* For next.config.ts only: the gateway the `/api` rewrite proxies to. No `server-only` here, as
|
|
* the config loads outside React. `next build` writes rewrites into its output, so the value is
|
|
* the one at build time (0018) and `SKIP_ENV_VALIDATION` can't skip it: a build without it fails
|
|
* here, rather than shipping a proxy to the wrong gateway.
|
|
*/
|
|
export function apiInternalUrl(): string {
|
|
const result = v.safeParse(origin, process.env.API_INTERNAL_ORIGIN);
|
|
if (result.success) return result.output;
|
|
throw new Error(
|
|
`API_INTERNAL_ORIGIN is needed to build: next.config rewrites /api to it and next build keeps the value (0018). ${result.issues[0].message}`,
|
|
);
|
|
}
|