1

I'm developing my first web app, using grunt, yo, angular.js, ... I also need some server-side service (which I will implement in PHP).

Which is the "standard" way to handle this scenario, which is - I suppose - quite widespread?
I mean, a setup which can be used both during development (grunt server for client-side, and apache for server-side) and production (apache or nginx server for both client-side and server side).

I make an example to clarify my doubts: I have an angular service like this:

var serverUrl = '//localhost:80';
app.factory('myFactory', function($resource) {
    $resource(serverUrl + '/api/getDataFromServer/:reqId', { ... }
);

While developing, I have two distinct servers for client-side (grunt on port 9000, for example), and server-side (apache on port 80, for example), so - to avoid CORS issues - I will have to - at least - add a header("Access-Control-Allow-Origin: http://localhost:9000") to server (JSON) output.

In production, conversely, I will have a single server to serve both static (angular app) and dynamic (data from PHP) content, so I will not need any additional Access-Control meta tag...

Of course I can take the current environment status (development / production) into account, and accordingly output or not the additional meta tag...

My question is: is this approach common with web apps (which need custom data services)? Do you follow a different approach, or do you see any 'architectural' improvement possible with this design?

MarcoS
  • 17,323
  • 24
  • 96
  • 174
  • Just a bit of info about an approach I took. I've used a combination of https://github.com/alanshaw/grunt-include-replace and https://github.com/changer/grunt-targethtml to help facilitate this kind of thing, but that was more about editing HTML. I call 'grunt dev' or 'grunt production' to do things differently in each scenario. Usually I have that many different DBs and potential deployment URLs I manually alter those in JS and Web.config, so nothing too sophisticated. – Adam Marshall May 09 '14 at 10:15
  • Thanks... I did just found also this SO answer: http://stackoverflow.com/a/18343298/709439, which I found very straightforward to differentiate among different environments directly inside Gruntfile.js. However, my question was more about the overall architecture... – MarcoS May 09 '14 at 10:32

0 Answers0