Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usage with socket.io #235

Open
Kaliph opened this issue Jan 4, 2020 · 1 comment
Open

usage with socket.io #235

Kaliph opened this issue Jan 4, 2020 · 1 comment

Comments

@Kaliph
Copy link

Kaliph commented Jan 4, 2020

I am trying to use redbird as a reverse proxy to horizontally scale my node.js application.

My redbird configuration looks like this so far.

`const proxy = require('redbird')({
port: env.PROXY_HTTP_PORT,
// Specify filenames to default SSL certificates (in case SNI is not supported by the
// user's browser)
xfwd: false,
ssl: {
port: env.PROXY_HTTPS_PORT,
key: "ssl/privkey.pem",
cert: "ssl/fullchain.pem",
}
});

proxy.register("localhost", "http://127.0.0.1:8081", {ssl: true});
proxy.register("localhost", "http://127.0.0.1:8082", {ssl: true});`

Then my express and socketio code looks like this.

`// HTTP
var serv = http.createServer(app)
.listen(env.WEBSERVER_PORT_MAIN, function () {
logger.info('Server listening on port ' + env.WEBSERVER_PORT_MAIN);
});

// HTTPS

var server = https.createServer({
key: fs.readFileSync('ssl/privkey.pem'),
cert: fs.readFileSync('ssl/fullchain.pem'),
ca: fs.readFileSync('ssl/fullchain.pem'),
requestCert: env.WEBSERVER_REQUEST_CERT,
rejectUnauthorized: env.WEBSERVER_REJECT_UNAUTHORIZED
}, app).listen(env.WEBSERVER_SECUREPORT_MAIN, function () {
logger.info('Secure Server listening on port ' + env.WEBSERVER_SECUREPORT_MAIN);
});

// launch Socket.io

var io = require('socket.io')(server);

io.on('connection', async function (socket) {

}`

My mainserver is listening on port 8081 for http traffic and 8444 is for https traffic. All http traffic gets redirected to https from my server.
The same applies for my backup server which is listening on port 8082 for http and 8445 for https traffic.
Socket.io is using my https server to start connections.

If I know get to https://localhost redbird redirects me to one of my servers redirecting my to

https://localhost:8444/login/index.html

for example.....

This works fine so far. When I now login into my webpage, the webpage starts using socket.io
then I get the following error in the browser console. It seems redbird is not yet handling my socket connection

Access to XMLHttpRequest at 'https://localhost/socket.io/?EIO=3&transport=polling&t=MzmUmft' from origin 'https://localhost:8444' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Any help on how to use redbird with socket.io would be helpful. Thankyou

@vorticalbox
Copy link

This is because the local host is not the same as the host of the server.

Just make your server set the header to fix this issue.

We have the same issue in development because angular app localhost:4200 is not the same as the server in docker localhost:3000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants