mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 09:13:11 +00:00
22 lines
771 B
TypeScript
22 lines
771 B
TypeScript
|
|
/** Absolute VITE_API_URL values must end with this segment (API_PATHS omit /api). */
|
||
|
|
export const ABSOLUTE_API_URL_SUFFIX = /\/api\/?$/;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Fails fast when an absolute VITE_API_URL omits the /api segment.
|
||
|
|
* Relative values (e.g. /api) are valid and skipped.
|
||
|
|
*/
|
||
|
|
export function assertAbsoluteApiUrlHasApiSegment(apiUrl: string | undefined): void {
|
||
|
|
const trimmed = apiUrl?.trim();
|
||
|
|
if (!trimmed?.startsWith("http")) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!ABSOLUTE_API_URL_SUFFIX.test(trimmed)) {
|
||
|
|
throw new Error(
|
||
|
|
`VITE_API_URL absolute URLs must end with /api (got: ${trimmed}). ` +
|
||
|
|
"API route paths do not include /api — set VITE_API_URL to the full API base, e.g. https://api.example.com/api. " +
|
||
|
|
"See README.md and .env.example.",
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|