H
H
hobu4ok912016-11-29 13:20:07
Angular
hobu4ok91, 2016-11-29 13:20:07

How to set proxy for backend in angular 2 cli?

I use openserver as backend.
The essence of the error: when going to the address localhost:4200/api, an error occurs Object Not Found Error 404
Creating a proxy.conf.json file with the content:

{
  "/api": {
    "target": "http://test.ru",
    "secure": false
  }
}

and running via ng serve --proxy-config proxy.conf.json did NOT help. I didn't find a solution on stackoverflow either.
How to solve the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Osher, 2016-11-29
@hobu4ok91

If the request from localhost:4200/api/foo/barshould fly to http://test.ru/foo/bar- then you need to add a line. And I would like to add one more.

{
  "/api": {
    "target": "http://test.ru",
    "pathRewrite": { "/api": "" }, // this line
    "changeOrigin": true, // and this too
    "secure": false
  }
}

V
Vitaly, 2016-11-29
@vitali1995

If I understood the problem correctly, you just need to configure apache using the .htaccess
file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question