1
0
mirror of synced 2025-12-21 10:57:10 -05:00
Files
docs/middleware/next.js
Peter Bengtsson 4e4b2d25c0 Next v12 (#24082)
* next v12

* stick to exact

* avoid segfault
2022-01-07 18:34:10 +00:00

28 lines
865 B
JavaScript

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