forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 1
/
releaseData.ts
26 lines (23 loc) · 1.12 KB
/
releaseData.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import {
ENABLE_STATIC_EXPORT,
IS_DEVELOPMENT,
NEXT_DATA_URL,
VERCEL_ENV,
} from '@/next.constants.mjs';
import type { NodeRelease } from '@/types';
const getReleaseData = (): Promise<Array<NodeRelease>> => {
// When we're using Static Exports the Next.js Server is not running (during build-time)
// hence the self-ingestion APIs will not be available. In this case we want to load
// the data directly within the current thread, which will anyways be loaded only once
// We use lazy-imports to prevent `provideBlogData` from executing on import
if (ENABLE_STATIC_EXPORT || (!IS_DEVELOPMENT && !VERCEL_ENV)) {
return import('@/next-data/providers/releaseData').then(
({ default: provideReleaseData }) => provideReleaseData()
);
}
// When we're on RSC with Server capabilities we prefer using Next.js Data Fetching
// as this will load cached data from the server instead of generating data on the fly
// this is extremely useful for ISR and SSG as it will not generate this data on every request
return fetch(`${NEXT_DATA_URL}release-data`).then(r => r.json());
};
export default getReleaseData;