4 ms·
Nice writeup. I tried to do the same thing a few months back and gave up. How did you handle getting your browser to talk to a server running on a different por
by davedx 12y ago
Nice writeup. I tried to do the same thing a few months back and gave up. How did you handle getting your browser to talk to a server running on a different port? (Cross-origin requests).
I have to say though, Rails used to be known for "convention over configuration", but when I've tried to use it lately I've found it becomes almost as complicated as configuring enterprise Java projects.
- jasonswett 12y agoI didn't have to do anything special to allow CORS, and now that I think of it I'm not sure why, because it's been necessary on other SPA projects I've been involved with. Maybe because both servers are localhost. That would be a good thing for me to figure out and include in the post. I'm kind of learning all this in public.
- deleted 12y ago[deleted]
- tragic 12y ago> How did you handle getting your browser to talk to a server running on a different port? (Cross-origin requests) Having run such things on entirely different servers, never mind localhost ports, what I needed to do was set the Access-Control-Allow-Origin http header in the rails controller (same principle applies to other frameworks). One simple guide is here: http://madhukaudantha.blogspot.co.uk/2011/05/access-control-allow-origin-in-rails.html http://madhukaudantha.blogspot.co.uk/2011/05/access-control-... Slightly ruined by that dreadful blogger interface, but there you go.
- mbell 12y ago> How did you handle getting your browser to talk to a server running on a different port? (Cross-origin requests). He's using grunt-connect-proxy to proxy the API requests through the grunt server so there are no CORS requests in this setup.
- patrickread 12y ago> How did you handle getting your browser to talk to a server running on a different port? (Cross-origin requests). https://github.com/cyu/rack-cors https://github.com/cyu/rack-cors I used that gem recently, and it fixed my issue. Just added the dev, prod hostnames explicitly in the origins list in my application.rb.
- cmpb 12y agoYou could just run the api on /api via an nginx proxy, that way it uses the same domain. I.e. catch all the traffic coming in to /api and route it to the proxy for you rails app.
- miles_matthias 12y agoI wrote about using Rails + AngularJS in a CORS way -- http://dojo4.com/blog/angularjs-service-rails-api http://dojo4.com/blog/angularjs-service-rails-api Hopefully it helps you!
- aantix 12y ago>I have to say though, Rails used to be known for "convention over configuration", but when I've tried to use it lately >I've found it becomes almost as complicated as configuring enterprise Java projects. Do you have any specific examples of where you were having troubles?