added wrapper to getInitialProps to prevent api calls in production
This commit is contained in:
1 parent
dded475c47
commit
fe5cc36182
12 files changed
+49
-33
No files matched your search
@@ -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')
|
||||
|
||||
|
||||
Reference in new issue
Block a user