首页 > 解决方案 > 错误连接 vue-socket ERR_CONNECTION_REFUSED

问题描述

我还没有设法将我的 vue js 连接到我的 nodejs 服务器。配置如下,服务器端:

const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);

app.use(express.static(__dirname + '/dist'));

app.set('port', process.env.PORT || 5050);

app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname + '/dist/index.html'));
});

server.listen(app.get('port'), () => console.log(`http://localhost:${app.get('port')}`));

在客户端:

Vue.use(new VueSocketio({
 debug: true,
 connection: 'http://localhost:5050'
}));

当我在本地测试一切正常时,套接字打开事件发出没有失败,问题出在我上传服务器时,不断出现错误:

vue-socketio.js:1 获取http://localhost:5050/socket.io/?EIO=3&transport=polling&t=MUu_7m4网络::ERR_CONNECTION_REFUSED

尝试输入服务器提供商的 ip 仍然是问题,我已经看到了很多关于此的问题,但我无法得到明确的解决方案,感谢他们给我的帮助,谢谢!

标签: node.jsvue.jssocket.io

解决方案


推荐阅读