added wrapper to getInitialProps to prevent api calls in production

This commit is contained in:
tmshv committed 2019-10-13 19:48:52 +03:00
1 parent dded475c47
commit fe5cc36182
12 files changed
+49 -33

No files matched your search

+16
View File
@@ -10,6 +10,22 @@ export async function requestGet(url, defaultResponse) {
}
}
/**
* This wrapper prevents fetching api request in static export mode and production environment
* because nextjs call getInitialProps on the client side
*
* @param {*} fn
*/
export function wrapInitialProps(fn) {
return async ctx => {
if (process.env.NODE_ENV === 'production' && process.browser) {
return __NEXT_DATA__.props.pageProps;
}
return fn(ctx)
}
}
export function createApiUrl(req, path) {
const { origin } = absoluteUrl(req, 'localhost:3000')