In angular 2 the cli to configure a proxy for a backend?

As backend I use openserver.
The error is: when you navigate to localhost:4200/api goes error Object Not Found Error 404
Create the file proxy.conf.json with the contents:
{
 "/api": {
 "target": "http://test.ru",
 "secure": false
}
}

and run through ng serve --proxy-config proxy.conf.json did NOT help. On stackoverflow, too, the solution is not found.
How to solve the problem?
July 2nd 19 at 13:27
2 answers
July 2nd 19 at 13:29
Solution
If the request is from localhost:4200/api/foo/bar needs to fly http://test.ru/foo/bar - then you have to add the line. And another is also desirable to add.
{
 "/api": {
 "target": "http://test.ru",
 "pathRewrite": { "/api": "" }, // this line
 "changeOrigin": true, // and this too
 "secure": false
}
}
Buddy, thank you! Direct rescued) - vladimir.Wucke commented on July 2nd 19 at 13:32
and where did you find Doc ? - nikita.Stracke commented on July 2nd 19 at 13:35
: the deductive method has determined that the only option - http-proxy-middleware. https://www.npmjs.com/package/http-proxy-middlewar... - vito.Hoeg commented on July 2nd 19 at 13:38
July 2nd 19 at 13:31
If understand correctly the problem, you just need to configure apache using the file .htaccess
I haven't work with apache, look into yourself modules with RewriteRule: statics give a direct route, and other addresses on probressive index.html
And where does Apache? I have the frontend side completely angular and backend yii2 it, ie, on the client side at all about php knows nothing. By the way when you click on the address test.ru (this address backend) yii2 app works fine. - vladimir.Wucke commented on July 2nd 19 at 13:34
You've got one page of the app gives - frontend or backend?) - nikita.Stracke commented on July 2nd 19 at 13:37
frontend - vito.Hoeg commented on July 2nd 19 at 13:40
What if I said the solution, if you're interested look) - vladimir.Wucke commented on July 2nd 19 at 13:43
OK, pardons) - lavon.Turn commented on July 2nd 19 at 13:46

Find more questions by tags ProxyOpen ServerAngular