mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 10:26:21 +00:00
28 lines
773 B
TypeScript
28 lines
773 B
TypeScript
const LOCAL_ENDPOINT = process.env.API_LOCAL_URL;
|
|
const REMOTE_ENDPOINT = process.env.API_REMOTE_URL;
|
|
|
|
const NOCTURNE_ENDPOINT = ((isServerSide = true) => {
|
|
if (process.env.NODE_ENV === 'production') {
|
|
if (isServerSide) {
|
|
return LOCAL_ENDPOINT;
|
|
} else {
|
|
return REMOTE_ENDPOINT;
|
|
}
|
|
} else {
|
|
return LOCAL_ENDPOINT;
|
|
}
|
|
});
|
|
|
|
export async function fetchNocturneApi(path: string, isServerSideRequest = true): Promise<{ code: number, ret: any }> {
|
|
let res = await fetch(`${ NOCTURNE_ENDPOINT(isServerSideRequest) }${ path }`, {
|
|
cache: 'no-cache'
|
|
});
|
|
|
|
if (!res.ok) {
|
|
return { code: res.status, ret: (await res.json()) };
|
|
}
|
|
|
|
return { code: res.status, ret: await res.json() };
|
|
}
|
|
|