I'm starting my first project with yo + grunt + angular.js.
I have a service that needs to read some data from my server; I built it using the angular $ http service. I also created a RESTful web service (implemented in PHP, but it could be Java, C, Perl, ..., it doesnβt matter), which provides an API for retrieving data.
The server from which grunt serves my ng application is currently (and probably will ever be) the same from which the PHP web service (from apache) is running.
I wonder if this is an acceptable architecture ... As a result, I have two different servers (grunt and apache) on the same server ... More, I always need to add "Access-Control-Allow-Origin: 127.0.0.1" to the output of my PHP service ...: - (
Is it possible, for example, to serve PHP from grunt?
UPDATE : I am talking about the development stage ... Of course, in production I would not use grunt ...
To better explain myself, I would like to use relative URLs in $ http () ... with the same code in the development and production phases ...
If in production I can expect it to work because I only have one server for the deployed angular application and PHP services that PHP should interpret in development when the angular application is served by Grunt? Soil yourself? If so, how?
UDPATE 2 and POSSIBLE SOLUTION : Having thought about this question a bit (and also having read this article), and having not received satisfactory answers here, I decided to use this approach:
- Development
- Use a production server (Apache, lighttpd, ...) to serve real PHP pages.
Use absolute URLs with the request $ http or $ to access this server (unlike Grunt, which serves angular.js pages). URLs will be easily configured to require only minimal work (and possible errors) to switch to production. - In PHP scripts before release (JSON), the corresponding header is always displayed "Access-Control-Allow-Origin"; the meaning of the directive will also be easy to configure.
- Production
- Deploy the angular.js application on the same server where PHP is deployed.
- Change the URLs and make them relative, as they now have the same origin with client scripts.
- Change the "Access-Control-Allow-Origin" header to allow only local requests (or, possibly, delete this header altogether ...).
I would be very happy if someone would like to comment on this decision, challenge it or offer the best ...
source share