我正在尝试使用SocketIO、Mongodb和NodeJS构建聊天应用程序。当我使用以下命令时,Web应用程序在
现在,我正在尝试使用我的
:80
上成功运行:
但是,SocketIO继续在浏览器控制台中发送错误,如下所示:docker run -d --name mongo mongo
docker run --name appname --link mongo:mongo -p 80:3000 -d docker_user/app
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>
我能在浏览器控制台看到消息连接到套接字,但是随后出现了错误消息,如下:
GET http://url/socket.io/?EIO=3&transport=polling&t=MOH41PY 404 (未找到)