我的服务器端应用程序托管在heroku
上:https://shielded-dusk-72399.herokuapp.com/
相关代码如下所示:
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
答案 0 :(得分:0)
您需要指定静态js文件的提供位置。例如,如果您将socket.io.js
文件放在/resources/js/
文件夹中,请添加以下内容:
app.use('/resources', express.static(path.join(__dirname, 'resources')))
然后您的文件将在http://localhost:8080/resources/js/socket.io.js