我服务器端应用程序已在heroku
托管:https://shielded-dusk-72399.herokuapp.com/不能获取客户端应用程序/socket.io/socket.io.js
相关的代码如下所示:
const
express = require('express'),
app = express(),
server = require('http').createServer(app),
io = require('socket.io').listen(server),
port = process.env.PORT || 8080
server.listen(port, (err) => {
console.log(err || 'listening on my very special port ' + port)
})
在我的Heroku此日志会记录:"listening on my very special port 28428"
现在我客户应用:
目前我的客户端应用程序正在端口8080
运行在我index.html
:
<script>/socket.io/socket.io.js" charset="utf-8"></script>
当我去localhost:8080
我收到以下错误:
Cannot GET http://localhost:8080/socket.io/socket.io.js
其他尝试:
<script src="https://shielded-dusk-72399.herokuapp.com:28428/socket.io/socket.io.js" charset="utf-8"></script>
Cannot GET https://shielded-dusk-72399.herokuapp.com:28428/socket.io/socket.io.js net::ERR_CONNECTION_REFUSED
<script src="https://shielded-dusk-72399.herokuapp.com:8080/socket.io/socket.io.js" charset="utf-8"></script>
Cannot GET https://shielded-dusk-72399.herokuapp.com:8080/socket.io/socket.io.js net::ERR_CONNECTION_REFUSED
然后我复制到./node_modules/socket.io-client/dist/socket.io.js
和resources/js
得到这个错误:
Cannot GET http://localhost:8080/resources/js/socket.io.js 404 (Not Found)
任何想法?
我使用所有这些作为参考,仍然上来短:
node.js /socket.io/socket.io.js not found
Node.js /socket.io/socket.io.js not found express 4.0
https://shielded-dusk-72399.herokuapp.com/ socket.io/socket.io.js似乎为我工作 – mineralwasser
哦,谢谢。我添加了一个端口号 而不是< script src =“http://shielded-dusk-72399.herokuapp.com/socket.io/socket.io.js”charset =“utf-8”> – user2456977