1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/custom-server-hapi/next-wrapper.js
2017-01-09 18:35:10 -08:00

35 lines
870 B
JavaScript

const { Readable } = require('stream')
function pathWrapper (app, pathName, opts) {
return function (hapiRequest, hapiReply) {
return new Promise((resolve, reject) => {
app.render(hapiRequest.raw.req, hapiRequest.raw.res, pathName, hapiRequest.query, opts)
.catch(error => {
reject(error)
})
.then(() => {
return hapiReply(new Readable().wrap(hapiRequest.raw.res))
})
})
}
}
function defaultHandlerWrapper (app) {
return function (hapiRequest, hapiReply) {
return new Promise((resolve, reject) => {
app.run(hapiRequest.raw.req, hapiRequest.raw.res)
.catch(error => {
reject(error)
})
.then(() => {
return hapiReply(new Readable().wrap(hapiRequest.raw.res))
})
})
}
}
module.exports = {
pathWrapper,
defaultHandlerWrapper
}