javascript - 使用未定义的 originalUrl 双重获取到 nodejs 服务器
问题描述
我正在获取对 nodeJS 后端的请求,以通过 mssql 库从 sql express 服务器查询数据。我通过 fetch 向服务器发出 2 个请求,首先是用户,然后是第一个承诺的 THEN 子句中的组,它工作正常。
问题是当 THEN 子句执行时,nodeJS 后端收到一个新请求(第三个),req.originalURL 的值为 /undefined。
如何避免对 nodeJS 的第三次调用?
function readGroups(){
const comando=`/grupos?id=1`
var grupos=fetch(comando); // generates a request.
// and nodeJS sends data back. Thats Ok
grupos.then(datos=>{ // But when I press F11 here it generates a new
// request to nodeJS with the req.originalURL
// with the value : /undefined
return datos.json().then(data=>{return data;});
}).then(datosJson=>{
crearListaGrupos(datosJson);
})
}
// Server side
app.get("*",(req,res)=>{
console.log(req.originalUrl); // it's /undefined
});
解决方案
推荐阅读
- java - Grails 唯一域约束
- vue.js - 如何在 vue js 中这样打印?
- powershell - Powershell用单引号调用cmd
- video - 如何将ffmpeg输出拆分为多个文件?
- regex - 删除所有不包含 bash 中电子邮件的行
- regex - 正则表达式获取字符串,除了单词之间
- mysql - AzerothCore DBand macOS:functions.sh:第 117 行:${1,,}:错误替换
- php - 在 Debian 上运行的 Ratchet PHP Websocket
- python - Python如何在numpy数组中查找第一个重复项
- ssl - 如何为flask api和客户端配置ssl证书