2017-04-03 86 views
0

服务器端应用程序已在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.jsresources/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

Can't get socket.io.js

+1

https://shielded-dusk-72399.herokuapp.com/ socket.io/socket.io.js似乎为我工作 – mineralwasser

+0

哦,谢谢。我添加了一个端口号 而不是< script src =“http://shielded-dusk-72399.herokuapp.com/socket.io/socket.io.js”charset =“utf-8”> – user2456977

回答

0

你需要从那里提供给您的静态的js文件中指定。举例来说,如果你放在socket.io.js文件在您/resources/js/文件夹,添加以下内容:

app.use('/resources', express.static(path.join(__dirname, 'resources'))) 

那么你的文件将可在