- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有人可以建议我如何设置它吗?这是场景。
我正在开发一个带有 Azure 移动服务后端的 Angular 应用。
在 Angular 中,我有指向移动服务 API 路径的资源。我有一个返回基本服务路径的配置工厂。我希望 dev/staging 槽指向 -dev api,生产槽指向生产 API 路径。
我可以创建两个配置工厂,但我不确定如何告诉它在暂存槽中使用开发工厂,在生产槽中使用生产工厂。对于带有服务器代码的 .net 应用程序,我会使用配置内容,或者可能是环境变量,但这都是客户端代码。
我以为只有两个网站,一个是从开发分支部署的,一个是从主分支部署的,并且有不同的配置...但是一旦我将开发合并到主分支,配置更改也会合并。
我不确定这是否重要,但我正在从 Visual Studio Online 进行部署作为构建的一部分。
我怎样才能做到这一点?
最佳答案
我能够解决这个同样的问题。我有开发、测试和生产环境,它们各自需要连接到不同的 API 端点。我能够使用名为 grunt-ng-constant 的 grunt 插件来完成此任务。
基本上,安装插件后,修改 Gruntfile 并在 grunt.initConfig
中添加如下内容:
ngconstant: {
// Options for all targets
options: {
space: ' ',
wrap: '"use strict";\n\n {%= __ngModule %}',
name: 'config',
},
// Environment targets
development: {
options: {
dest: '<%= yeoman.app %>/scripts/config.js'
},
constants: {
ENV: {
name: 'development',
apiEndpoint: 'http://your-development.api.endpoint:3000'
}
}
},
production: {
options: {
dest: '<%= yeoman.dist %>/scripts/config.js'
},
constants: {
ENV: {
name: 'production',
apiEndpoint: 'http://api.livesite.com'
}
}
}
},
像这样注册 Grunt 任务:
grunt.registerTask('serve', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'ngconstant:development', // ADD THIS
'bower-install',
'concurrent:server',
'autoprefixer',
'connect:livereload',
'watch'
]);
});
现在,每次运行 gruntserve
时,它都会生成一个 config.js 文件,其中包含您的开发常量。您可以配置不同的任务,例如 grunt 测试
或 grunt 生产
来生成测试或生产常量。
最后,将 config.js 添加到 index.html 中,如下所示:
<script src="/scripts/config.js" />
并在您的应用程序中注册配置模块:
var app = angular.module('myApp', [ 'config' ]);
在你的 Controller 中,你可以像这样获取“环境”变量:
angular.module('myApp')
.controller('MainCtrl', function ($scope, $http, ENV) { // ENV is injected
$scope.login = function() {
$http.post(
ENV.apiEndPoint, // Our environmental var :)
$scope.yourData
).success(function() {
console.log('Cows');
});
};
});
通过这种方法,您可以轻松地自动化整个部署管道。您可以让 CI 服务器将您的更改推送到适当的服务器并构建正确版本的应用程序。
这是一个非常有用的资源供您阅读,我从中获取了代码示例:http://mindthecode.com/how-to-use-environment-variables-in-your-angular-application
希望这对您有帮助!
关于angularjs - 如何在 Azure 网站中拥有测试和生产 AngularJS 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30486088/
我在一个网站上工作,该网站在生产中只有 aspx 文件和 bin 目录和文件。任何人都知道这个网站是如何部署的,我通常有我的网站,我也会提交代码。 我的问题 2. 如何在同一台服务器上创建测试网站?我
您好,我认为这应该是一个相当简单的问题,但我对管理 git 不太熟悉。 我使用的是非常流行的 http://nvie.com/posts/a-successful-git-branching-mode
目前我的网站(生产服务器)已经有很多代码了。现在我想开始在我的项目中使用 Git 并为我的团队设置一个暂存服务器。谁能给我任何建议? 这是我脑海中的画面: Production
我目前正在学习 Erlang SO 用户能否提供有关他们的任何 Erlang 应用程序部署的有趣示例? 我想深入了解 Erlang 在过去的电信中的常见用途,以及 Erlang 在开发/部署过程中带来
我关注了Ryan's screencast并部署到 VPS。所以我使用 Unicorn + nginx + github + Ubuntu 12.04 LTS + capistrano。我也使用 i1
我想在 Azure 中维护临时环境和生产环境。每个都应该有自己的 blob 存储和 sql 存储。实现这一目标的最佳方法是什么?设置临时和生产 SQL Server 以及两个 Blob 存储帐户? 最
我无法使用 Electron 打包程序在内置的 Electron 应用程序中打开chrome开发工具。 我已经尝试过mainWindow.webContents.openDevTools(),但这没有
我有一个 Azure 应用程序服务环境。 可以在同一个 ASE 中运行多个应用服务计划(开发、测试和生产)吗? 基本上,我知道他们会共享前端池,我认为这很好,因为那里没有运行应用程序代码,并且它“..
我是 Maven 新手,有 Rails 背景。在较高级别上,如果我正在运行测试、在本地运行应用程序以及在部署到生产环境时,我希望连接到不同的数据库。 这就是我的想法。当我运行 mvn test 时,它
我有一个 Azure 应用程序服务环境。 可以在同一个 ASE 中运行多个应用服务计划(开发、测试和生产)吗? 基本上,我知道他们会共享前端池,我认为这很好,因为那里没有运行应用程序代码,并且它“..
我正在使用 faSTLane\produce 脚本制作一个新应用程序,我收到以下错误消息: in `parse_response': {"data"=>nil, "messages"=>{"warn"
使开发人员能够构建包含私有(private)数据的系统的当前做法是什么?谁能指出这类事情的“最佳实践”指南? 我们这里有一个 Catch-22,因为开发人员需要编写与具有被认为是“私有(private
我有一个连接 Azure SQL Server 的 Azure 云服务。当我第一次设置这个时,我真的不太了解自己在做什么,只是想熟悉 Azure。所以现在我想利用我所拥有的东西并将其转变为可靠的部署结
我是 Cordova 的新手。抱歉,如果这些是业余问题。我想详细了解典型手机应用程序的设置和架构。 我有一个本地版本的 Meteor Cordova 正在运行,它通过 Modulus 连接到远程服务器
我一直在寻找一些在一些 POS(销售点)设备和服务器之间同步数据的选项。 SymmetricDS似乎是具有商业友好许可证的选项之一。作为一个 Codehaus 项目确实保证了一定程度的质量,所以我同意
在 PHP 开发中,可以通过服务器的“环境”变量确定应用程序是在生产环境还是开发环境中运行。 在 tomcat 服务器上是否有类似的变量可用,或者是否有更好的方法将应用程序用于生产和开发? 最佳答案
我正在做一个项目,我需要使用 TwitterAPI 检索 Twitter 消息,处理它们并将它们存储在数据库中。我正在使用 Producer/Consumer BlockingQueue,其中元素的作
这个问题类似于:iPhone development - what is the difference between a development and distribution provision
我正在尝试根据 URL 在 Drupal 中设置环境。例如,如果我访问 mysite.local,它将使用 localdb 并将站点名称更改为“Local Mysite”;如果我转到 mysite.c
我今天一直在阅读 Magento 中的数据库同步。 我目前正在努力解决的一件事是在开发期间和上传到生产期间需要同步什么。现在假设一批更改将包含对数据库和类似代码的更改,下面是我对模型工作流的理解(我目
我是一名优秀的程序员,十分优秀!