forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.js
28 lines (21 loc) · 809 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
28
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