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.
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')
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?
Most helpful comment
I think protocol shouldn't be included: