2017-12-05 18:42:57 +00:00
|
|
|
const { parse } = require('url')
|
2017-01-10 02:35:10 +00:00
|
|
|
|
2017-12-05 18:42:57 +00:00
|
|
|
const nextHandlerWrapper = app => {
|
2017-02-13 02:12:32 +00:00
|
|
|
const handler = app.getRequestHandler()
|
2017-12-05 18:42:57 +00:00
|
|
|
return async ({ raw, url }, h) => {
|
|
|
|
await handler(raw.req, raw.res, url)
|
|
|
|
return h.close
|
|
|
|
}
|
2017-02-13 02:12:32 +00:00
|
|
|
}
|
2017-12-05 18:42:57 +00:00
|
|
|
const defaultHandlerWrapper = app => async ({ raw: { req, res }, url }) => {
|
|
|
|
const { pathname, query } = parse(url, true)
|
|
|
|
return app.renderToHTML(req, res, pathname, query)
|
|
|
|
}
|
|
|
|
|
|
|
|
const pathWrapper = (app, pathName, opts) => async ({ raw, query, params }) => {
|
|
|
|
return app.renderToHTML(raw.req, raw.res, pathName, { ...query, ...params }, opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { pathWrapper, defaultHandlerWrapper, nextHandlerWrapper }
|