Angular CORS request blocked

前端 未结 5 438
独厮守ぢ
独厮守ぢ 2020-12-14 23:22

I am trying to connect my Angular app with a simple REST server on express. The server only sends json data in reply to request. To add CORS suppor

5条回答
  •  渐次进展
    2020-12-15 00:03

    In case you are using angular-cli, you can use a proxy:

    proxy.conf.json:

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

    Will redirect all requests with /api prefix to localhost:8888 without any cors issue.

    Offical docs: https://angular.io/guide/build#proxying-to-a-backend-server

提交回复
热议问题