forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext-wrapper.js
More file actions
28 lines (26 loc) · 752 Bytes
/
next-wrapper.js
File metadata and controls
28 lines (26 loc) · 752 Bytes
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
const nextHandlerWrapper = app => {
const handler = app.getRequestHandler()
return async ({ raw, url }, h) => {
await handler(raw.req, raw.res, url)
return h.close
}
}
const defaultHandlerWrapper = app => async ({ raw: { req, res }, url }, h) => {
const { pathname, query } = url
const html = await app.renderToHTML(req, res, pathname, query)
return h.response(html).code(res.statusCode)
}
const pathWrapper = (app, pathName, opts) => async (
{ raw, query, params },
h
) => {
const html = await app.renderToHTML(
raw.req,
raw.res,
pathName,
{ ...query, ...params },
opts
)
return h.response(html).code(raw.res.statusCode)
}
module.exports = { pathWrapper, defaultHandlerWrapper, nextHandlerWrapper }