Socket.io: io.origins() does not take an array of strings

Created on 3 Mar 2018  ·  4Comments  ·  Source: socketio/socket.io

You want to:

  • [x] report a bug
  • [ ] request a feature

Current behaviour

In the documentation it states, that io.origins() takes an array of strings/origins (see example https://socket.io/docs/server-api/#server-origins-value), when in fact it does not. It only works when providing a string instead of an array.

Steps to reproduce (if the current behaviour is a bug)

Setting

io.origins(['http://localhost:3000'])

and then connecting from localhost:3000 does not work.

It only works when setting io.origins('http://localhost:3000')

Expected behaviour

Setup

  • OS: macOS High Sierra 10.13.3
  • browser: Chrome 64.0.3282.186
  • socket.io version: 2.0.4

Most helpful comment

I think protocol shouldn't be included:

io.origins(['localhost:3000', 'localhost:3001']);
// or
io.origins('localhost:3000');

All 4 comments

I think protocol shouldn't be included:

io.origins(['localhost:3000', 'localhost:3001']);
// or
io.origins('localhost:3000');

Works with protocol when provided as a string, does not when provided in an array 😄

But thanks for clarification!

I think it's implemented with an indexOf, hence the funky behaviour.

I'll add a note in the documentation.

I just ran into the same issue - an array with the protocol in the URL, eg io.origins([https://subdomain.domain.ee:*]) doesn't work, while io.origins([subdomain.domain.ee:*]) works.

Whilst the example in the documentation includes https:// in the array example: io.origins(['https://foo.example.com:443']); .

Looking at this commit, it seems that the docs were changed to include that example, yet it still happened to me?

I was using [https://subdomain.domain.ee:*] as the URL, which didn't work, nor did it with http:// (although in my case it should be only accessible via https:// anyway). Once I removed the protocol, it started working.

I thought I'd report this here just in case. Was I possibly missing something?

Was this page helpful?
0 / 5 - 0 ratings