未验证 提交 ef637b38 编写于 作者: B Bruno Bernardino 提交者: GitHub

Fixes Hapi custom server example (#15292)

上级 7a266a91
......@@ -5,14 +5,6 @@ const nextHandlerWrapper = (app) => {
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 },
......@@ -28,4 +20,7 @@ const pathWrapper = (app, pathName, opts) => async (
return h.response(html).code(raw.res.statusCode)
}
module.exports = { pathWrapper, defaultHandlerWrapper, nextHandlerWrapper }
module.exports = {
pathWrapper,
nextHandlerWrapper,
}
......@@ -2,17 +2,20 @@ import Link from 'next/link'
export default function Home() {
return (
<ul>
<li>
<Link href="/b" as="/a">
<a>a</a>
</Link>
</li>
<li>
<Link href="/a" as="/b">
<a>b</a>
</Link>
</li>
</ul>
<>
<ul>
<li>
<Link href="/b" as="/a">
<a>a</a>
</Link>
</li>
<li>
<Link href="/a" as="/b">
<a>b</a>
</Link>
</li>
</ul>
<img src="/logo.svg" width="200" />
</>
)
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 884 200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"><path d="M440.75,50c-34.5,0 -59.375,22.5 -59.375,56.25c0,33.75 28,56.25 62.5,56.25c20.844,0 39.219,-8.25 50.594,-22.156l-23.907,-13.813c-6.312,6.907 -15.906,10.938 -26.687,10.938c-14.969,0 -27.688,-7.813 -32.406,-20.313l87.562,0c0.688,-3.5 1.094,-7.125 1.094,-10.937c0,-33.719 -24.875,-56.219 -59.375,-56.219Zm-29.563,45.313c3.907,-12.469 14.594,-20.313 29.532,-20.313c14.968,0 25.656,7.844 29.531,20.313l-59.063,0Zm366.063,-45.313c-34.5,0 -59.375,22.5 -59.375,56.25c0,33.75 28,56.25 62.5,56.25c20.844,0 39.219,-8.25 50.594,-22.156l-23.906,-13.813c-6.313,6.907 -15.907,10.938 -26.688,10.938c-14.969,0 -27.687,-7.813 -32.406,-20.313l87.562,0c0.688,-3.5 1.094,-7.125 1.094,-10.937c0,-33.719 -24.875,-56.219 -59.375,-56.219Zm-29.531,45.313c3.906,-12.469 14.593,-20.313 29.531,-20.313c14.969,0 25.656,7.844 29.531,20.313l-59.062,0Zm-121.969,10.937c0,18.75 12.25,31.25 31.25,31.25c12.875,0 22.531,-5.844 27.5,-15.375l24,13.844c-9.938,16.562 -28.563,26.531 -51.5,26.531c-34.531,0 -59.375,-22.5 -59.375,-56.25c0,-33.75 24.875,-56.25 59.375,-56.25c22.938,0 41.531,9.969 51.5,26.531l-24,13.844c-4.969,-9.531 -14.625,-15.375 -27.5,-15.375c-18.969,0 -31.25,12.5 -31.25,31.25Zm257.75,-90.625l0,143.75l-28.125,0l0,-143.75l28.125,0Zm-768.031,-15.625l115.468,200l-230.937,0l115.469,-200Zm288.687,15.625l-86.594,150l-86.593,-150l32.468,0l54.125,93.75l54.125,-93.75l32.469,0Zm184.094,37.5l0,30.281c-3.125,-0.906 -6.438,-1.531 -10,-1.531c-18.156,0 -31.25,12.5 -31.25,31.25l0,46.25l-28.125,0l0,-106.25l28.125,0l0,28.75c0,-15.875 18.469,-28.75 41.25,-28.75Z" style="fill-rule:nonzero;"/></svg>
\ No newline at end of file
const next = require('next')
const Hapi = require('@hapi/hapi')
const {
pathWrapper,
defaultHandlerWrapper,
nextHandlerWrapper,
} = require('./next-wrapper')
const { pathWrapper, nextHandlerWrapper } = require('./next-wrapper')
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
......@@ -32,16 +28,10 @@ app.prepare().then(async () => {
handler: nextHandlerWrapper(app),
})
server.route({
method: 'GET',
path: '/static/{p*}' /* use next to handle static files */,
handler: nextHandlerWrapper(app),
})
server.route({
method: '*',
path: '/{p*}' /* catch all route */,
handler: defaultHandlerWrapper(app),
handler: nextHandlerWrapper(app),
})
try {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册