简体   繁体   中英

Socket.io + Webapp Different Containers Docker on Heroku ( 404 Not Found )

I deployed my project in docker containers of Heroku.

web.1: static file connecting to socket.io

server.1: socket.io connecting to mongo atlas

server.js

const io = require('socket.io')(server, {
    cors: {
        origin: '*',
    },
    transports: ["xhr-polling"]
});

...

server.listen(process.env.PORT || 3000, () => {
    console.log(`listening on *:${process.env.PORT}`);
});

client.js

var socket = io.connect();

I can't connect. I search here in Stackoverflow and I understand Heroku define the ports to connection, but I have two containers running in same domain. One in port 80 (static website) and other in random port generated by Heroku ( socket.io Server ).

Help?

This is not possible in Heroku: you can only deploy one Dyno per web application, therefore using only one port (the one dynamically assigned by Heroku).
Moreover, you cannot hardcode port numbers (ie 80).

In your case you could create 2 Dynos or host the web site (if it is static) on GitHub.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM