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

io.origins() does not take an array of strings #3190

Closed
1 of 2 tasks
stnwk opened this issue Mar 3, 2018 · 4 comments · Fixed by #3198
Closed
1 of 2 tasks

io.origins() does not take an array of strings #3190

stnwk opened this issue Mar 3, 2018 · 4 comments · Fixed by #3198

Comments

@stnwk
Copy link

stnwk commented Mar 3, 2018

You want to:

  • 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
@darrachequesne
Copy link
Member

I think protocol shouldn't be included:

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

@stnwk
Copy link
Author

stnwk commented Mar 5, 2018

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

But thanks for clarification!

@stnwk stnwk closed this as completed Mar 5, 2018
@darrachequesne
Copy link
Member

darrachequesne commented Mar 9, 2018

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

I'll add a note in the documentation.

darrachequesne added a commit to darrachequesne/socket.io that referenced this issue Mar 10, 2018
Previously, the protocol was not taken in account, which caused the following behaviour:

```js
io.origins('https://foo.example.com:443'); // ok as a string
io.origins(['https://foo.example.com:443'); // not ok as an array
```

Fixes socketio#3190
darrachequesne added a commit to darrachequesne/socket.io that referenced this issue Mar 10, 2018
Previously, the protocol was not taken in account, which caused the following behaviour:

```js
io.origins('https://foo.example.com:443'); // ok as a string
io.origins(['https://foo.example.com:443'); // not ok as an array
```

Fixes socketio#3190
darrachequesne added a commit that referenced this issue Mar 10, 2018
Previously, the protocol was not taken in account, which caused the following behaviour:

```js
io.origins('https://foo.example.com:443'); // ok as a string
io.origins(['https://foo.example.com:443'); // not ok as an array
```

Fixes #3190
@githubuser88442
Copy link

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?

dzad pushed a commit to dzad/socket.io that referenced this issue May 29, 2023
Previously, the protocol was not taken in account, which caused the following behaviour:

```js
io.origins('https://foo.example.com:443'); // ok as a string
io.origins(['https://foo.example.com:443'); // not ok as an array
```

Fixes socketio#3190
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

Successfully merging a pull request may close this issue.

3 participants