简体   繁体   English

Azure:Web 应用程序 - 从部署的 nodejs 应用程序中列出应用程序设置

[英]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.

相关问题 为作为网络应用程序部署的Google Apps脚本创建设置的最佳方法 - best way to create settings for a google apps script deployed as web app nodeJS 应用程序作为多个 web 应用程序的微服务 - nodeJS app as microservice for multiple web apps 部署为网络应用程序的两个Google应用程序脚本之间的localStorage访问 - localStorage access between two google app scripts deployed as web apps 从表单谷歌应用程序脚本Web应用程序动态列表 - google apps script web app dynamic list from form 在 Azure Web App 中的 javascript 中配置设置/内置于 Azure DevOps - Configuring settings in javascript in Azure Web App / built in Azure DevOps 对部署在 Azure 上的 nodejs 服务器的请求尝试访问 Azure Postgres 灵活数据库时应用服务超时 - Requests to nodejs server deployed on Azure App Service timing out when trying to access Azure Postgres flexible database 如何使用 NodeJS 在 web 应用程序中从 Azure blob 存储中提供 HTML 文件? - How can I serve an HTML file from Azure blob storage in a web app using NodeJS? 如何从部署为网络应用的Google应用脚本中打开电子表格 - How to open spreadsheet from Google app script deployed as web app 无法访问Azure Web App Linux或Windows上的NodeJS站点 - Can't reach NodeJS site on Azure Web App Linux or Windows MVC Web应用程序的设置 - Settings of MVC web application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM