【发布时间】:2019-03-01 07:16:02
【问题描述】:
我正在尝试使用 SocketIO、Mongodb 和 NodeJS 构建一个聊天应用程序。当我使用时,Web 应用程序在 :80 上成功运行:
docker run -d --name mongo mongo
docker run --name appname --link mongo:mongo -p 80:3000 -d docker_user/app
但 SocketIO 继续在浏览器控制台中发送错误,例如:
GET http://url/socket.io/?EIO=3&transport=polling&t=MOH41PY 404 (Not Found)
我的index.js 看起来像:
var express = require('express');
var http = require('http').Server(app);
const https = require('https');
var io = require('socket.io')(http);
const mongo = require('mongodb').MongoClient;
var request = require('request');
var path = require('path');
var app = express();
// Set Static path...
app.use(express.static(path.join(__dirname, '/public')));
//Connect to mongo...
mongo.connect('mongodb://mongo:27017/team_chat_data', function(err,db){
if(err){
throw(err);
}
//Rest of logic...
});
app.listen(3000, function(){
console.log('Server started on port :3000');
});
现在,我正在尝试使用我的index.html 连接到我的服务器:
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>
<script>
// Connect to socket.io
var socket = io.connect('http://url:80');
// Check for connection
if(socket !== undefined){
console.log('Connected to socket...');
// Handle Output
socket.on('output', function(data){
console.log(data);
});
</script>
我能够在我的浏览器控制台中看到消息 Connected to socket 但随后出现如下错误消息:
GET http://url/socket.io/?EIO=3&transport=polling&t=MOH41PY 404 (Not Found)
【问题讨论】: