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

CORS support #78

Closed
joshwcomeau opened this issue Jan 28, 2018 · 2 comments
Closed

CORS support #78

joshwcomeau opened this issue Jan 28, 2018 · 2 comments

Comments

@joshwcomeau
Copy link

joshwcomeau commented Jan 28, 2018

Hi there! Thanks for the great tool, was delighted when Max told me this existed :)

I've run it on my digitalocean droplet, but I'd like to use it for sites on Github Pages. When I try to make a fetch request for it, I get a CORS error:

Cross-origin redirection to https://server-ip-address/my-path denied by Cross-Origin Resource Sharing policy: Origin http://localhost:3002 is not allowed by Access-Control-Allow-Origin.

It looks like a PR was opened last year, #17, which fixed this by adding the right header. Looking through the current source, though, I don't see that header being sent. Was it intentionally removed? If so, is there a way to specify allowed origins that I'm missing?

Happy to open a quick PR if necessary!

@joshwcomeau
Copy link
Author

joshwcomeau commented Jan 28, 2018

Oh, hm, I spoke too soon; the header still exists. Not sure why it isn't working for me!

Will dig into it a bit.

If it helps, here's my request code, on localhost:

  componentDidMount() {
    const url = `http://server-ip-address${window.location.pathname}`;

    fetch(url)
      .then(response => response.json())
      .then(({ views }) => this.setState({ hits: views }))
      .catch(err => console.log('Error retrieving hit counter stats:', err));
  }

@joshwcomeau
Copy link
Author

Ah-ha! Figured it out, I wasn't specifying the port in server-ip-address. Without the port it was trying to access the server's main page, which is HTTPS, and that redirection was failing.

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

1 participant