如何使 Angular 应用程序从私有云代工厂(运行时)读取环境变量 [英] how to make angular application read environment variables from private cloud foundry (Runtime)
本文介绍了如何使 Angular 应用程序从私有云代工厂(运行时)读取环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 angular 5 应用程序并部署到私有云代工厂.通常,在构建应用程序时,我们会在 "environment.{*}.ts" 文件中提供 API 端点并运行 npm run build --prod 命令.
I am working with angular 5 application and deploying to private cloud foundry. In general, while building the application we would provide API endpoint in "environment.{*}.ts" file and run npm run build --prod command.
我的要求是在部署后读取用户提供的环境变量.我是 PCF 的新手.
my requirement is to read user provided environment variables after deployment. I am new to PCF.
提前致谢.
到目前为止我尝试过的链接,Link1、Link2,Link3
Links I have tried so far, Link1, Link2,Link3
推荐答案
我写了一个 博客文章 关于这个.简而言之:
I wrote a blogpost about this. In short:
- fork staticfile-buildpack
- 将
data.go
更改为包括:
- Fork the staticfile-buildpack
- Change the
data.go
to include:
location /inject {
default_type application/json;
return 200 '<%= ENV["INJECT"] %>';
}
- 在 CF 中使用 json 设置环境变量INJECT"
cf push
with-b [你的分叉仓库]
- 通过包含
Staticfile
在 buildpack 中启用 SSI - 将 SSI 添加到您的 Angular
index.html
以包含此内容: - Set a environment var "INJECT" with json in CF
cf push
with-b [your forked repo]
- enable SSI in the buildpack by including a
Staticfile
- Add a SSI to your angular
index.html
to include this:
<html>
<head>
<script type="text/javascript">window["INJECT"] =
<!--#include virtual="/inject" -->
</script>
这篇关于如何使 Angular 应用程序从私有云代工厂(运行时)读取环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文