How to enable Access-Control-Allow-Origin for angular 5/nodejs?

前端 未结 4 537
名媛妹妹
名媛妹妹 2021-01-20 16:43

Read many ways for including of \'Access-Control-Allow-Origin\' and none worked for me.

I use @angular/common/http module and external url as data source. by the att

4条回答
  •  天命终不由人
    2021-01-20 17:11

    You mentioned webpack-dev-server, which of course can handle CORS since it's using express behind the scenes. In your webpack config

    devServer: {
      headers: {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
        "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
      }
    },
    

提交回复
热议问题