我目前正在尝试使用 Node 重定向到外部站点,并在 get 调用中专门表达。但是,我似乎无法找到可能的解决方案。任何帮助,将不胜感激。请注意,在尝试 response.redirect 时,我收到 TypeError: res.redirect is not a function。但是,当我查看 express 文档时,它似乎就在那里。
app.get('/:urlToForward', (res, req, next)=>{
//Stores the value of param
// var shorterUrl = res.params.urlToForward;
// shortUrl.findOne({'shorterUrl': shorterUrl}, (err,data)=>{
// // if (err) {
// // res.send("This shorterUurl does not exist.");
// // }
// // else {
// // res.redirect(301, data.originalUrl);
// // }
// // response.end();
// });
res.redirect('https://www.google.com');
});
最佳答案
参数中的顺序很重要。 req 必须在前面,然后是 res,然后是 next。
app.get('/:urlToForward', (req, res, next)=>{ ...
关于javascript - res.redirect 不是 express 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43034673/