1
0
mirror of synced 2025-12-22 11:26:57 -05:00
Files
docs/middleware/next.js
2022-09-22 15:55:30 -04:00

29 lines
809 B
JavaScript

import next from 'next'
const { NODE_ENV } = process.env
const isDevelopment = NODE_ENV === 'development'
export const nextApp = next({ dev: isDevelopment })
export const nextHandleRequest = nextApp.getRequestHandler()
await nextApp.prepare()
function renderPageWithNext(req, res, next) {
// We currently don't use next/image for any images.
// We don't even have `sharp` installed.
// This could change in the future but right now can just 404 on these
// so we don't have to deal with any other errors.
if (req.path.startsWith('/_next/image')) {
return next(404)
}
const isNextDataRequest = req.path.startsWith('/_next') && !req.path.startsWith('/_next/data')
if (isNextDataRequest) {
return nextHandleRequest(req, res)
}
return next()
}
export default renderPageWithNext