我正在尝试将 Express 应用程序迁移到 hapi.js,但我的路线遇到了问题。我只想要 2 GET :我的索引“/”,以及所有不是“/”的内容重定向到“/”。
使用 Express 我有这个:
// static files
app.use(express.static(__dirname + '/public'));
// index route
app.get('/', function (req, res) {
// whatever
}
// everything that is not /
app.get('*', function(req, res) {
res.redirect('/');
});
我在使用 hapi.js 时遇到问题,无法获得相同的行为。我的“静态道路”是这样的:
server.route({
method: 'GET',
path: '/{path*}',
handler: {
directory: {
path: 'public',
listing: false
}
}
});
我的“404路”是:
server.route({
method: 'GET',
path: '/{path*}',
handler: function (request, reply) {
reply.redirect('/');
}
});
我收到此错误:
Error: New route /{path*} conflicts with existing /{path*}
我该如何解决这个问题?