H
H
hobu4ok912016-11-11 05:49:04
Angular
hobu4ok91, 2016-11-11 05:49:04

How to set up a proxy on the backend server on the angular 2 cli?

after ng serve, the localhost:4000 server is started, it is necessary that when accessing localhost:4000/api or another port, the request goes to my local openserver to a domain, for example, test.ru. How to set up proxying tell me?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
romych2004, 2016-11-13
@romych2004

Create proxy.conf.json file

{
  "/api": {
    "target": "http://localhost:3000",
    "secure": false
  }
}

In package.json, specify in the scripts block:
Now instead of ng serve run the command
npm start

A
averkoff, 2021-03-11
@averkoff

The actual way to connect a proxy for the angular cli is described in the documentation Proxying to a backend server Now you do not need to edit the package.json file , create a proxy.conf.json and connect it via angular.json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question