我正在尝试使angularjs应用程序的12因子与配置(http://12factor.net/config)兼容。
它应该取决于环境,并且在代码中我不会看到单词development
,test
,production
等。
例如,变量可以存储在bash env
中。我可以将它们传递给网络服务器。
我已经想到将.erb模板文件转换为erb config.js.erb > config.js
,但是如果我在应用程序运行时更改了变量,则必须重做。
我已经找到此文章http://mindthecode.com/how-to-use-environment-variables-in-your-angular-application/
但这是一个很大的谎言,Grunt.js确实可以做到这一点,无论如何...
我知道不是为前端应用程序创建12factor的哲学,但是我的有角度的应用程序可以部署在许多环境中的许多不同服务器中,并且不会损害任何人正确地做事:)。
谢谢!
编辑:
我想使用的配置参数将是一些类似的东西:
app:
api:
url: "The url of the api server"
port: 8080
cdn:
images: "url of my images caching service"
google:
oauth:
"api_key": "The api key used for that deployment"
#other external frontend services
其他编辑:
[这个家伙有点回答:http://bahmutov.calepin.co/inject-valid-constants-into-angular.html,我觉得这很丑陋,完全与angularjs绑定;但它有效!