9 lines
403 B
TypeScript
9 lines
403 B
TypeScript
/** Fetch wrapper for absolute app paths when Next.js basePath is enabled. */
|
|
export function appFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
|
|
if (typeof input !== 'string' || !input.startsWith('/') || input.startsWith('//')) {
|
|
return fetch(input, init);
|
|
}
|
|
const basePath = process.env.NEXT_PUBLIC_APP_BASE_PATH ?? '';
|
|
return fetch(`${basePath}${input}`, init);
|
|
}
|