我正在使用react和node进行我的第一个项目,并且在这个问题上停留了一段时间。尝试使用ip地址连接到我的站点时,我一直收到此错误,但是如果我只是执行localhost:3000,则可以正常工作。我希望能够通过IP地址进行连接,以便可以跨设备进行测试。这是完整的错误:
[HPM] Error occurred while trying to proxy request /socket.io/?EIO=3&transport=polling&t=N4EqtUl&sid=kz_I098ZM2h1Z6WZAAAI from 192.168.0.4:3000 to http://192.168.0.4:5000 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)
我结帐了this后,像建议的第二个答案一样实现了setupProxy.js,但仍然无法正常工作。
这是我的节点服务器(index.js):
const express = require('express');
const app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
const path = require('path')
const port = process.env.PORT || 5000;
app.use(express.static(path.join(__dirname, 'client/build')));
io.on('connection', function(socket) {
console.log('a user connected');
});
// Anything that doesn't match the above, send back index.html
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/client/build/index.html'))
})
http.listen(port || 5000, function () {
console.log('listening on', port);
});