我正在尝试将我的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('/');
});
Run Code Online (Sandbox Code Playgroud)
我有hapi.js的问题,以获得相同的行为.我的"静态路"看起来像这样:
server.route({
method: 'GET',
path: '/{path*}',
handler: {
directory: {
path: 'public',
listing: false
}
}
});
Run Code Online (Sandbox Code Playgroud)
而我的"404道路"将是:
server.route({
method: 'GET',
path: '/{path*}',
handler: function (request, reply) {
reply.redirect('/');
}
});
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Error: New route /{path*} conflicts with existing /{path*}
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?