Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it better to use CORS or nginx proxy_pass for a RESTful client-server app?

Tags:

cors

proxy

I have a client-server app where the server is a Ruby on rails app that renders JSON and understands RESTful requests. It's served by nginx+passenger and it's address is api.whatever.com.

The client is an angular js application that consumes these services (whatever.com). It is served by a second nginx server and it's address is whatever.com.

I can either use CORS for cross subdomain ajax calls or configure the client' nginx to proxy_pass requests to the rails application.

Which one is better in terms of performance and less trouble for developers and server admins?

like image 536
Rafael Vega Avatar asked Oct 04 '22 17:10

Rafael Vega


1 Answers

Unless you're Facebook, you are not going to notice any performance hit from having an extra reverse proxy. The overhead is tiny. It's basically parsing a bunch of bytes and then sending them over a local socket to another process. A reverse proxy in Nginx is easy enough to setup, it's unlikely to be an administrative burden.

You should worry more about browser support. CORS is supported on almost every browser, except of course for Internet Explorer and some mobile browsers.

Juvia uses CORS but falls back to JSONP. No reverse proxy setup.

like image 103
Hongli Avatar answered Oct 10 '22 02:10

Hongli