gpt4 book ai didi

angular - 如何在 Angular 中访问 Azure 静态 Web 应用程序应用程序设置?

转载 作者:行者123 更新时间:2023-12-02 22:57:26 24 4
gpt4 key购买 nike

我将 Angular 应用程序作为静态 Web 应用程序部署到 Azure 中。现在我想使用配置中的应用程序设置来更改环境中的变量。ts 可以访问不同的 API 和 Application Insights,而无需每次都更改代码。

enter image description here

环境.ts

export const environment = {
production: true,
SERVER_API_URL: 'https://backend01.azurewebsites.net',
DEVELOPER_OPTIONS: true,
ENABLE_PROD_MODE: true,

appInsights: {
instrumentationKey: '<key>'
}
};

我想更改 instrumentationKeySERVER_API_URL。这可以通过应用程序设置实现吗?有人知道如何做到这一点吗?

谢谢:)

最佳答案

可以使用 NPM 包,但是在以下 stackoverflow 问答中强烈警告不要使用它:how to use Azure App Configuration in Angular

另一种可能性是使用 JSON 文件,如下例(相当旧,但有效):https://devblogs.microsoft.com/premier-developer/angular-how-to-editable-config-files/ .

目前看来,Azure 静态网站中的环境变量仅支持服务器端代码,如此链接中的 MS 文档(第一个 azure 框)。 https://learn.microsoft.com/en-us/azure/static-web-apps/application-settings

根据下图,您可以探索的另一种方法是:创建一个可以读取配置设置的 azure 函数,然后在 Angular 应用程序启动时调用该 azure 函数来提供您需要的应​​用程序设置。不过我可以想象会有catch22的情况.. enter image description here

关于angular - 如何在 Angular 中访问 Azure 静态 Web 应用程序应用程序设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72487292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com