P
P
Programep2018-03-01 21:30:08
Yii
Programep, 2018-03-01 21:30:08

How to make Angulajs and Yii2 REST API on the same web server?

Good afternoon!
I am developing an application on Angularjs and Yii2 Rest API.
Now I'm running the application through webpack on the same machine I'm developing on. The Yii2 Rest API server runs on nginx on another machine, so I had to add the following lines to the nginx config:

add_header Access-Control-Allow-Origin "http://localhost:4200";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
add_header Access-Control-Allow-Headers "Keep-Alive,Content-Type";
add_header Access-Control-Expose-Headers "Content-Type";

so that the browser does not write a CORS error.
Now I see the following solution to this problem:
make REST Api in Yii2 in a separate controller,
and bind the assembled AngularJS application to another controller, for example, SiteController.
Please tell me on these questions:
1. Is my solution correct for this problem?
2. Where is it better to do routing in angularjs or yii (now there are routing developments in angularjs)?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question