Ng2 has a problem with setting up a proxy service on its own. ~

follow the course, still request mock data of less than 8000 port
"data of port 8000 can be requested directly to
, but request 8000 port

at port 4001.

clipboard.png
clipboard.png
clipboard.png

clipboard.png,

help me with some suggestions

Mar.01,2021

"/api":{
    "target":"",
    "secure": false,
    "changeOrigin": true
}

the document is here: https://doc.webpack-china.org.

is the request to 8000, but there is no request for the interface?
http.get ('/ api/products') will request localhost:8000/api/products . If you want to request localhost:8000/products , you should add pathRewrite .


1proxy.conf.js<br>2

{
    "/api":{
        "target":"http://localhost:8000",
        "secure": false,
        "changeOrigin": true
    }
}

3. In the package.json file
"start": "ng serve-- proxy-config proxy.conf.json",

4, npm run start remember that it must be run start, not ng serve,. I cried foolishly by myself

Menu