Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 两个问题,1。在express router 2.0上,请求、响应_Node.js_Reactjs_Express_Nginx - Fatal编程技术网

Node.js 两个问题,1。在express router 2.0上,请求、响应

Node.js 两个问题,1。在express router 2.0上,请求、响应,node.js,reactjs,express,nginx,Node.js,Reactjs,Express,Nginx,[环境] node.js, 表示 反应 nginx [第一项问题] 如果我重新加载了除根url之外的网站,我会得到一个错误“无法获取/…” [第二项问题] 当我通过ajax向服务器端请求了6次以上时,网站停止并且没有响应。如果我重新启动我的服务器,我可以再次从服务器得到5次响应。。。 这个错误对我来说太关键了 我的密码。。! [客户] //对服务器的请求 fetchInfo=async()=>{ const{id}=this.props.params; constroom=wait webs

[环境] node.js, 表示 反应 nginx

[第一项问题] 如果我重新加载了除根url之外的网站,我会得到一个错误“无法获取/…”

[第二项问题] 当我通过ajax向服务器端请求了6次以上时,网站停止并且没有响应。如果我重新启动我的服务器,我可以再次从服务器得到5次响应。。。 这个错误对我来说太关键了

我的密码。。! [客户]


//对服务器的请求
fetchInfo=async()=>{
const{id}=this.props.params;
constroom=wait webster.get(“/api/v1/conference/”+id);
这是我的国家({
信息:房间
});
}
//get-ajax
函数get(url、数据){
const get=$.ajax({
网址,
数据
键入:“获取”,
数据类型:“json”,
});
const error=get.fail(()=>{
抛出新错误(“请求中出现错误”);
});
const info=get.done(信息=>{
退货信息;
});
返回信息| |错误;
}

关于您的第一个问题

如果我重新加载了除根url之外的网站,我会得到一个错误“无法获取/…”

这是意料之中的,因为当您在路由器链接中导航时,Javascript会运行并操纵地址栏中的URL,而不会导致页面刷新,而页面刷新又会进行页面转换

解决方案是采用“一网打尽”的方式

只需在服务器上设置一个catch all,将所有请求发送到index.html

像这样的

app.get('/*', function (req, res) {
    res.sendFile(path.join(__dirname, '/../../client/build', 'index.html'));
});
但请确保在rest api之后执行此路由


关于第二个问题,它非常不清楚,如果我想猜测一下,我认为请求的处理程序被卡住了,在您结束它之前不会响应客户端

我终于找到了错误的代码!这些都在方法“getRoomInfo”中。