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

Multiple origins in options #130

Closed
adammw opened this issue Jan 24, 2011 · 9 comments
Closed

Multiple origins in options #130

adammw opened this issue Jan 24, 2011 · 9 comments

Comments

@adammw
Copy link

adammw commented Jan 24, 2011

Hi,
Could multiple origins be supported in a later version of Socket.IO-node so we may specify either an array of origins or a comma separated list of origins?

Thanks.

@rauchg rauchg closed this as completed Jun 22, 2011
@mikekhristo
Copy link

What was the verdict on this?

@Gut6
Copy link

Gut6 commented Mar 5, 2014

I've had the same problem. There is nothing about that in docs but it's already available in socket.io.
It should be a list with spacebars.
Example:
io.set('origins', 'http://domain.com:* http://domain.org:* http://domain.net:* http://domain.gov:*');

Those :* are important. Without it, it will not work.

@LordMajestros
Copy link

The :* is for specifying ports and yes it won't work without it.

@rakusai
Copy link

rakusai commented Nov 16, 2018

@Gut6 FYI, your sample code cause security issues.

io.set('origins', 'http://domain.com:* http://domain.org:* http://domain.net:* http://domain.gov:*');

will be processed at here

~this._origins.indexOf(parts.hostname + ':*') ||

so omain.com, main.com, ain.com will be passed.

You must use array instead of string, like this:
io.set('origins', ['domain.com:*', 'domain.org:*', 'domain.net:*', 'domain.gov:*']);

@rvanbaalen
Copy link

This won't work in the latest version of socket.io.

You can now pass the array of allowed origins in the io server config like this:

const io = require("socket.io")(httpServer, {
    cors: {
        origin: ['http://localhost:*', 'http://anotherdomain.com:*'],
    },
});

@yuvalkabeli
Copy link

This won't work in the latest version of socket.io.

You can now pass the array of allowed origins in the io server config like this:

const io = require("socket.io")(httpServer, {
    cors: {
        origin: ['http://localhost:*', 'http://anotherdomain.com:*'],
    },
});

real good help for me even a year later, thanks!

@ezraimanuel
Copy link

This won't work in the latest version of socket.io.
You can now pass the array of allowed origins in the io server config like this:

const io = require("socket.io")(httpServer, {
    cors: {
        origin: ['http://localhost:*', 'http://anotherdomain.com:*'],
    },
});

real good help for me even a year later, thanks!

yeppp... the same. many thanks!

@taffil
Copy link

taffil commented Sep 26, 2022

This won't work in the latest version of socket.io.

You can now pass the array of allowed origins in the io server config like this:

const io = require("socket.io")(httpServer, {
    cors: {
        origin: ['http://localhost:*', 'http://anotherdomain.com:*'],
    },
});

This is my code, and wont work on live or dev server

const io = require("socket.io")(http, {
    cors: {
        origin: [
            "https://www.domain.com:*",
            "https://www.dev-domain.com:*",
        ],
        methods: ["GET", "POST"],
    },
});

@darrachequesne
Copy link
Member

@taffil this should be:

const io = require("socket.io")(http, {
    cors: {
        origin: [
            "https://www.domain.com",
            "https://www.dev-domain.com",
        ],
        methods: ["GET", "POST"],
    },
});

The extra ̀:* is not taken in account.

Reference: https://socket.io/docs/v4/server-options/#cors

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