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

Bypassing CORS error #56

Open
yannp opened this issue May 3, 2017 · 1 comment
Open

Bypassing CORS error #56

yannp opened this issue May 3, 2017 · 1 comment

Comments

@yannp
Copy link

yannp commented May 3, 2017

Hi,

I would like to use rack-reverse-proxy in order to bypass a CORS error while accessing youtube via ajax from my website. I have the following JS code client-side:

    xhr = xhr.open 'GET', '/watch?v=0xc3XdOiGGI', true

    xhr.onload = ->
      console.log("XHR SUCCESS")
      return

    xhr.onerror = ->
      console.log("XHR ERROR")
      return

    xhr.send()

And the following Ruby on Rails code server-side:

    config.middleware.insert(0, Rack::ReverseProxy) do
      reverse_proxy_options preserve_host: true
      reverse_proxy '/watch', 'http://youtube.com/'
    end

I'm still getting a CORS error on the client-side. I've been playing with different reverse_proxy_options but couldn't make it work so far.

Is it possible to achieve this with rack-reverse-proxy? Which options should I use?

Thanks for your help

@nuk
Copy link

nuk commented Jun 25, 2018

Try disabling the preserve_host option. Whilst solving another issue I've discovered that setting it to false is what trully keep the doamin in the request to the target machine.

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

2 participants