运行Express JS的Azure App Service中的CORS标头 [英] CORS Headers in Azure App Service running Express JS

查看:75
本文介绍了运行Express JS的Azure App Service中的CORS标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个简单的Web应用程序,该应用程序必须跨跨某些站点进行跨源资源共享.该应用程序在应用程序服务的Azure云中运行.现在,我已通过以下方式将Azure门户和Express服务器应用程序中的CORS标头设置为中间件:

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(); });

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(); });

我的问题是,我可以从Express App中删除CORS标头,而仅使用Azure App Service提供的标头吗?谢谢.

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.

推荐答案

是的,您绝对可以通过在Azure门户中设置CORS标头或通过在您的应用中添加CORS标头来实现.

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

为了方便其他人,在这里,我还提供了以下步骤来从Azure门户设置CORS标头.

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

  1. 导航到 Azure门户网站.
  2. 导航到您的应用服务.
  3. API 菜单中单击 CORS .
  4. 在空白的允许的来源文本框中输入每个URL.创建一个新的文本框.
  5. 点击保存.
  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.

这篇关于运行Express JS的Azure App Service中的CORS标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆