node.js - 错误连接 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 仍然是问题,我已经看到了很多关于此的问题,但我无法得到明确的解决方案,感谢他们给我的帮助,谢谢!
解决方案
推荐阅读
- ipython - Spyder 4.2.5 - iPython 控制台不适用于 Python 3.8.0
- python - 如何使 for 循环使用由 if 语句创建的新列表
- javascript - 删除为未定义。你能帮助我吗?拖放什么都不做
- elasticsearch - Elasticsearch 获得具有相同字段值的最大 n 个结果
- angular - 每个复选框显示两次
- flutter - Flutter 的 GlobalKeys 列表
- java - 如何在 kotlin 中将类转换为 ((Int,String) -> Unit )
- azure-iot-hub - 设置叶/父关系
- python - 使用csv模块将python转换为exe时遇到错误
- java - Retrofit2 访问内部对象数组