forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.js
27 lines (20 loc) · 865 Bytes
/
next.js
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
27
import next from 'next'
// This import is necessary, as of Jan 2022 to avoid a segmentation fault.
// Next is suppose to automatically pick up the `next.config.js` file
// but if you don't specify it to the `next()` constructor you currently
// get a seg fault.
// Possibly relevant: https://github.com/vercel/next.js/issues/33008
import conf from '../next.config.js'
const { NODE_ENV } = process.env
const isDevelopment = NODE_ENV === 'development'
export const nextApp = next({ dev: isDevelopment, conf })
export const nextHandleRequest = nextApp.getRequestHandler()
await nextApp.prepare()
function renderPageWithNext(req, res, next) {
const isNextDataRequest = req.path.startsWith('/_next') && !req.path.startsWith('/_next/data')
if (isNextDataRequest) {
return nextHandleRequest(req, res)
}
return next()
}
export default renderPageWithNext