How to send CORS headers with Devise if user not authorized (401 response)

后端 未结 2 1293
栀梦
栀梦 2020-12-28 17:36

I am working on an app, where server and the api-consuming client reside under different domains, so I would like to use CORS. To do so, I have to set corresponding http hea

相关标签:
2条回答
  • 2020-12-28 17:55

    I successfully used the rack-cors gem https://github.com/cyu/rack-cors and outlined my experience on my blog.

    Punchline: Specify middleware order so cors handler is before warden:

    config.middleware.insert_before Warden::Manager, Rack::Cors
    
    0 讨论(0)
  • 2020-12-28 18:07

    We generally disliked CORS headers. We prefer using HAProxy to to redirects.

    With HAProxy you can set up all requests coming to website.com/api/ to be internally redirected to your rails machine.

    frontend main *:80
      acl api      path_beg  -i /api
      acl app      path_beg  -i /app
    backend app_backend
      reqrep    ^([^\ ]*)\ /app/(.*)  \1\ /\2
      balance   roundrobin
      server    app_files smartphoneapp.localhost:8000
    backend api_backend
      reqrep    ^([^\ ]*)\ /api/(.*)  \1\ /\2
      balance   roundrobin
      server    app_api localhost:3000
    
    0 讨论(0)
提交回复
热议问题