Azure中的React和AppSettings [英] React and AppSettings in Azure

查看:81
本文介绍了Azure中的React和AppSettings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是从Azure应用程序设置(如api_url)中检索一些环境密钥.

My goal is to retrieve some environnement keys from Azure Application settings like api_url.

我的构建工厂如下:

  • 用于tsx的Webpack以缩小js
  • 使用VSTS构建和发布
  • 在Azure Web App上部署

Azure Web App上没有运行node.js,它只是为index.html,bundle.js和资产提供服务的静态服务器.

There is no node.js running on Azure Web App, it is just a static server that serve index.html, bundle.js and assets.

我尝试了这种不同的方法:

I have tried this different method :

  1. 在此示例下方,如果我加载系统变量,则可以检索此键/值.我已经尝试将dotenv-webpack和systemvars设置为true,但未加载任何内容,显然我没有Node.js服务器.

  1. Below this example, if I load system vars, I will be able to retrieve this key/value. I have tried with dotenv-webpack and systemvars to true but nothing is loaded, obviously I don't have a nodejs server.

我找到了一个网址 https://mywebsite.scm.azurewebsites. net/api/settings 为我提供包含所有设置(包括自定义应用程序设置)的JSON.所以我的问题是,无论是在实时运行时(此URL受帐户凭据保护,我可以从Web应用程序访问)还是在构建过程中,如何获取此信息,但在这种情况下,如何从VSTS访问? p>

I've found an url https://mywebsite.scm.azurewebsites.net/api/settings that give me a JSON with all settings, including custom appsettings. So my question is how I can get this, whether in live runtime (this url is protected by account credentials, can I access from web app), or maybe in built process, but in this case, how to access from VSTS ?

感谢您的帮助.

推荐答案

要获取具有所有设置的JSON,您可以从reactjs应用向该URL发送GET请求:

To get a JSON with all settings you could send a GET request from your reactjs App to this URL:

https://$AZURE_LOGIN:$AZURE_PASS@$AZURE_APPNAME.scm.azurewebsites.net/api/settings

用户名和密码可从应用服务门户中的部署凭据中找到:

The username and password can be found from Deployment Credentials in the portal of your App Service:

这篇关于Azure中的React和AppSettings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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