mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
35 lines
870 B
JavaScript
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
|
|
}
|