Azure Slot部署的Angular 2配置问题 [英] Angular 2 configuration issues with Azure Slot deployments

查看:110
本文介绍了Azure Slot部署的Angular 2配置问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Angular环境变量和Azure插槽时遇到了问题

I'm having a problem with Angular environment variables and Azure Slots

我们想使用提供静态Angular文件的应用程序服务,并且还希望使用Azure插槽来使我们的部署更安全.

We want to use an app service providing static Angular files and we also want to use Azure slots to make our deployments safer.

我们要使用广告位的原因是:

The reasons we want to use slots are:

  1. 在使代码对所有人完全可用之前,请确保代码在生产环境中有效
  2. 将停机时间减少到几乎为零,因为在上线"阶段没有部署任何构建

我们的Angular站点仅提供静态文件,这意味着插槽部署需要不同的版本才能为每个插槽以不同的方式填充env.json环境设置.

Our Angular site only serving up static files means that slot deployments require a different build to populate the env.json environment settings differently for each slot.

我们正在考虑的解决方案是在同一个Angular网站中创建一个端点,并从Angular站点返回其原始位置进行调用以获取其配置.这种方式可以在Azure的登台和生产插槽中进行不同的设置,并且只需要一个Angular构建.

The solution we're thinking of taking is to create an endpoint in the same Angular website and make a call from the Angular site back to its origin to get its configuration. This way configuration can be set differently in the staging and production slots in Azure and only one Angular build would be required.

我们需要一些服务器端代码来选择这些Azure应用程序设置,并将其提供回站点的终结点中.我们尚未决定用于创建该端点的技术-我们目前正在考虑.Net Core或NodeJ,因为它们似乎非常适合Angular产品和开发团队.

We need some server side code to pick up these Azure Application settings and provide them back in an endpoint on the site. We are yet to make a decision about the technology we use to create that endpoint - we are thinking either .Net Core or NodeJs at the moment because they seem to fit well with the Angular product and the development team.

是否有人有插入服务器端组件来为以前的静态Angular网站提供配置的经验?

Does anyone have any experience of plugging in a server side component to provide configuration for a previously static Angular website?

推荐答案

要实现您的要求,您只需将以下PHP文件放入您的站点根文件夹.然后通过Angular应用将GET请求发送到端点http://<websitename>.azurewebsites.net/appSettings.php.这将为您提供一个JSON对象,其中包含所有应用设置.

To achieve your requirement, you can just put the following PHP file to your site root folder. Then send a GET request to endpoint http://<websitename>.azurewebsites.net/appSettings.php via your Angular app. This will give you a JSON Object that contains all App settings.

appSettings.php

appSettings.php

<?php

$appSettings = [];

foreach ($_SERVER as $key => $value) {

    if(preg_match('/^APPSETTING_/', $key)) {
        $appSettings[str_replace('APPSETTING_', '', $key)] = $value;
    }
}

header('Content-Type: application/json');
echo json_encode($appSettings);

这篇关于Azure Slot部署的Angular 2配置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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