[英]Azure: Web Apps - List Application Settings from deployed nodejs app
I've deployed a nodeJs app to a Linux Azure AppService.我已将 nodeJs 应用程序部署到 Linux Azure AppService。 Now I would like to list the server settings of that same app-service.现在我想列出同一个应用服务的服务器设置。 Under the Identity
tab I enabled the managed Identity for this AppService.在Identity
选项卡下,我为此 AppService 启用了托管身份。 In my NodeJs App I've tried the following:在我的 NodeJs 应用程序中,我尝试了以下操作:
const { DefaultAzureCredential } = require("@azure/identity");
const credential = new DefaultAzureCredential();
credential.getToken().then(token => {
...
});
I'm not really sure what this is doing, but I don't think it connects, because the getToken
never resolves.我不太确定这是在做什么,但我认为它没有连接,因为getToken
永远不会解析。 Any suggestions what I'm missing here?有什么建议我在这里缺少的吗?
If you want to get server setting values inside of the app service, you can just try process.env.NODE_ENV
as this doc indicated.如果您想在应用程序服务中获取服务器设置值,您可以尝试process.env.NODE_ENV
, 如此文档所示。 Instead of calling Azure management API.而不是调用Azure管理API。
If you want to get server setting values outside of the app service, your code can't access server setting values directly, so you should call Azure management API.如果您想在应用服务之外获取服务器设置值,您的代码无法直接访问服务器设置值,因此您应该调用 Azure 管理 API。 If you have some problem with DefaultAzureCredential
, you can try ClientSecretCredential
.如果DefaultAzureCredential
有问题,可以尝试ClientSecretCredential
。 Just try the code below:只需尝试以下代码:
const { ClientSecretCredential } = require("@azure/identity");
const fetch = require("node-fetch")
let tenantId='';
let clientID = '';
let clientSecret = '';
let subscriptionID = ''
let resourceGroup = ''
let appServiceName = ''
new ClientSecretCredential(tenantId,clientID,clientSecret).getToken(['https://management.azure.com/.default']).then(result=>{
accessToken = result.token
reqURL = `https://management.azure.com/subscriptions/${subscriptionID}/resourceGroups/${resourceGroup}/providers/Microsoft.Web/sites/${appServiceName}/config/appsettings/list?api-version=2019-08-01`
fetch(reqURL, {
method: 'post',
headers: { 'Authorization': 'Bearer ' + accessToken},
})
.then(res => res.json())
.then(json => console.log(json));
})
Result:结果:
For how to create an Azure AD app and assign a role to it so that it could have permission to call Azure mgmt APIs, see this doc .有关如何创建 Azure AD 应用程序并为其分配角色,以便它可以有权调用 Azure 管理 API,请参阅此文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.