访问Node.js中的Azure ServiceConfiguration设置 [英] Accessing Azure ServiceConfiguration settings in Node.js

查看:65
本文介绍了访问Node.js中的Azure ServiceConfiguration设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将进入构建通过Windows Azure上的iisnode运行的Node.js应用程序的beta部署阶段.设置了多个实例以及生产/阶段分离后,我的研究使我得出以下结论:

I'm coming to the beta deployment phase of building a Node.js application running through iisnode on Windows Azure. Having set up multiple instances, as well as production/staging separation, my research has led me to the following conclusion:

如果我想在不重新部署代码的情况下即时更改配置设置,则需要使用服务配置 .cscfg 文件.

我的问题是我已将各种配置设置存储在 web.config < appSettings> < iisnode> 元素中>我可能想要更改的内容,这些内容当前通过流程全局对象显示在我的Node应用程序中.

My problem is that I've stored various configuration settings in the <appSettings> and <iisnode> elements of web.config that I might want to change, which are currently exposed in my Node application via the process global object.

我环顾了 MSDN 节点文档SO (通常),并且不能查找节点是否可以或可以以相同的方式公开服务配置设置.如果没有,是否可以将它们公开给我的应用程序?

I've looked around MSDN, Node documentation and SO (the usual), and can't find if Node does or can expose Service Configuration settings in the same way. If not, is there a way I can expose them to my application?

具体来说,我实际上只是想将 node_env 设置从 web.config 移至服务配置",因为我希望能够仅通过配置更改就可以从登台切换到生产设置.原因-我们使用IP交换在暂存和生产之间进行交换,两者之间有一些非常小的差异(例如,它消耗的RESTful Web服务的URL).

To be more specific, I'm really only looking to move the node_env setting from web.config to Service Configuration, since I'd like to be able to switch from staging to production setup with just a config change. The reason - we're using IP switching to swap between staging and prod, and there are some very minor differences between the two (the URL of the RESTful web service it consumes, for example).

我也知道我可以在iisnode读取的 iisnode.yaml 文件中配置 node_env ,但这仍将回收应用程序,并且我不想修改 x yaml文件并重新部署,其中 x 是生产/登台应用程序的实例数.

I also know I can configure node_env in an iisnode.yaml file read by iisnode, but that will still recycle the application, and I don't want to modify x yaml files and redeploy, where x is the number of instances of the production/staging application.

推荐答案

您可以通过Azure SDK for Node.js访问配置设置.

You can access the configuration settings via the Azure SDK for Node.js.

要安装:

npm install azure

要获取配置设置:

var azure = require('azure');

azure.RoleEnvironment.getConfigurationSettings(function(error, settings) {
  if (!error) {
    // You can get the value of setting "setting1" via settings['setting1']
  }
});

这篇关于访问Node.js中的Azure ServiceConfiguration设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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