Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allowing cross-domain calls with Yeoman (1.0) grunt server

I've been using Yeoman 0.9 up until yesterday when I decided to use the beta 1.0 release on OS X. I use Yeoman to develop an angular app.

With the Yeoman 0.9-->1.0 migration of my app done and working, I'm now keen to extend the dev server fired up by yeoman grunt server to allow me to make cross-domain calls to an API developed by another team, hosted on another server, where they've already allowed cross-domain calls. Up to now we've been using a fake http backend courtesy of angular.js.

--An aside--

If anyone's reading this looking for a quick solution, we got cross-domain calls working by passing the --disable-web-security option to Chrome from the command line using this approach on OS X with Chrome, but it turns off security for all of Chrome (thumbs down) and we can't get Chrome to fire up as a new instance anyway.

--End aside--

Through some digging I found this Stack Overflow post (via the answer to this post) giving me a pretty good idea on what I need to do to get grunt server allowing cross-domain calls. It essentially involves adding a middleware component to connect to allow alter the headers so that "Access-Control-Allow-Origin" is set to "*" or whatever one likes.

Knowing nothing about Node.js, I can see the change alluded to in the post needs to be made somewhere in the many files created by Yeoman, but where? I've done some raw string searches for "app.configure" and "connect.listen" within the "node_modules" directory set up by Yeoman but I come up with a number of hits, most of which are from examples bundled with the modules and it isn't clear to me which I should edit. In case it helps, here's a snapshot of the directory structure for my angular app:

enter image description here

If anyone can give me some pointers on where these changes may be made I'd really appreciate it!

like image 611
coderigo Avatar asked Feb 19 '13 06:02

coderigo


2 Answers

Solved sans messing around with node using the approach in this github pull request: http://github.com/angular/angular.js/pull/1454

like image 113
coderigo Avatar answered Oct 06 '22 19:10

coderigo


You can use Apache proxy and connect your REST server with gruntjs(angular.js).

Apache would do this:

  • proxy / -> gruntjs
  • proxy /service -> REST server

you would use your application hitting Apache and angular.js application would think that is talking with itself so no cross domain problem.

Here is a great tutorial on how to set this up: http://alfrescoblog.com/2014/06/14/angular-js-activiti-webapp-with-activiti-rest/

like image 36
user3420847 Avatar answered Oct 06 '22 19:10

user3420847