node.js - res.redirect 附加到当前 url 不打开该 url
问题描述
所以我的代码如下
router.get('/:id', async function (req, res){
try {
const id = req.params.id;
const student = await firestore.collection('urls').doc(id);
const data = await student.get();
var updatedviews = data.data().views +1;
var updatedloc = data.data().location;
fetch(ip)
.then(async function(response) {
response.json().then(async jsonData => {
updatedloc += jsonData.region_code;
await student.update({
views: updatedviews,
location: updatedloc
})
});
})
.catch(function(error) { });
if(!data.exists) {
res.status(404).send('Url with the given ID not found');
}else {
return res.redirect(data.data().longurl);
}
} catch (error) {
res.status(400).send(error.message);
}
});
但它的作用是将我从数据库中获取的长 url 附加到当前 url,如 localhost:5000/{longurl}
我想要的是它应该只在浏览器窗口中打开 {longurl}
解决方案
推荐阅读
- reactjs - 使用 componentDidMount 或从另一个文件调用未说明的函数
- google-apps-script - 如何在 Google 表格中实现 VBA 所有排序?
- arrays - 将数值数组转换为字符元胞数组并在一行中与字符连接
- less - 从 LESS 中的值列表生成 CSS 类
- python - if 语句导致事情失败
- xamarin - 设置 HtmlWebViewSource html 属性
- c++ - 自行卸载的 Linux 共享库
- yaml - 为空的json数组对象创建swagger yaml
- ios - Detect which instruction may cause error in my app ios
- ssh - 使用 SSH -T 在远程主机上执行脚本时出现“未设置 TERM 环境变量”错误