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