2

I'm building a simple web application which has to Cross Origin Resource Sharing restricted to some sites. The app is running in the Azure cloud on an App Service. Right now I have set the CORS headers from both the Azure portal and the Express server app as a middleware in the following way:

app.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); });

My question is, that can I remove the CORS headers from the Express App and use only the headers which are provided by the Azure App Service? Thanks.

Tyhjis
  • 23
  • 1
  • 5

2 Answers2

4

Yes, definitely you can achieve it either by setting CORS headers from the Azure portal or by adding CORS headers from your App.

For other people’s convenience, here I also provide the following steps to set CORS header from the Azure portal.

  1. Navigate to the Azure portal.
  2. Navigate to your App Service.
  3. Click CORS in the API menu.
  4. Enter each URL in the empty ALLOWED ORIGINS text box. A new text box is created.
  5. Click Save.

enter image description here

Aaron Chen
  • 9,835
  • 1
  • 16
  • 28
0

They don't recommend to use both enter image description here

Cesar Moran
  • 123
  • 1
  • 9