概要
Meteorアプリケーションの実行時に設定できる環境変数について調べたメモです。
なお、いくつかの環境変数は動作確認が取れていません。
環境
- Windows7 (64bit)
- Meteor 1.2.1
参考
- [meteor/meteor - github] (https://github.com/meteor/meteor/tree/master)
- [Meteor Docs] (http://docs.meteor.com/#/full/)
- [Environment Variables] (http://www.meteorpedia.com/read/Environment_Variables)
環境変数
環境変数はprocess.env
オブジェクトで管理されます。(これはnode.jsの機能です。)
たとえば、アプリケーションの実行前に下記の環境変数を登録すると、アプリケーションからはprocess.env.MY_ENV
として参照することができます。
> set MY_ENV=foo
> meteor
process.env
オブジェクトにユーザーの環境変数を追加する処理はrun-app.jsで行われています。
_computeEnvironment: function () {
var self = this;
var env = _.extend({}, process.env);
env.PORT = self.port;
env.ROOT_URL = self.rootUrl;
env.MONGO_URL = self.mongoUrl;
...省略...
env.METEOR_PRINT_ON_LISTEN = 'true';
// use node's path module and not 'files.js' because NODE_PATH is an
// environment variable passed to an external process and needs to be
// constructed in the OS-style.
var path = require('path');
env.NODE_PATH =
self.nodePath.join(path.delimiter);
return env;
},
ROOT_URL
アプリケーションのURLをROOT_URL
環境変数で指定します。
> set ROOT_URL=http://foo.example.com
[Meteor.absoluteUrl] (http://docs.meteor.com/#/full/meteor_absoluteurl)
The server reads from the ROOT_URL environment variable to determine where it is running.
PORT
アプリケーションがリッスンするhttpポートをPORT
環境変数で指定します。デフォルトは3000です。
( Windowsでは反映されませんでした。)
specifying the HTTP port for the application to listen on
> set PORT=8000
PORT
環境変数の代わりに--port
を使うことができます。
(こちらは反映されました。)
> meteor --port=8000
METEOR_SETTINGS
アプリケーション固有の設定情報をMETEOR_SETTINGS
環境変数で指定します。
( Windowsでは反映されませんでした。)
この環境変数にはjson形式の値を設定する必要があります。
> set METEOR_SETTINGS="{\"public\":{\"for\":\"bar\"},\"private\":{\"hoge\":\"fuga\"}}"
linux系では下記のようにsettings.jsonファイルの内容を設定することもできます。
$ export METEOR_SETTINGS="$(cat settings.json)"
METEOR_SETTINGS
環境変数の代わりに--settings
を使用することができます。
(こちらは反映されました。)
> meteor --settings=settings.json
[Meteor.settings] (http://docs.meteor.com/#/full/meteor_settings)
When running your server directly (e.g. from a bundle), you instead specify settings by putting the JSON directly into the METEOR_SETTINGS environment variable.
参照箇所のソースコード(抜粋)
Meteor = {
isClient: false,
isServer: true,
isCordova: false
};
Meteor.settings = {};
if (process.env.METEOR_SETTINGS) {
try {
Meteor.settings = JSON.parse(process.env.METEOR_SETTINGS);
} catch (e) {
throw new Error("METEOR_SETTINGS are not valid JSON: " + process.env.METEOR_SETTINGS);
}
}
// Make sure that there is always a public attribute
// to enable Meteor.settings.public on client
if (! Meteor.settings.public) {
Meteor.settings.public = {};
}
HTTP_FORWARDED_COUNT
プロキシーサーバー経由でアクセスするクライアントのIPアドレスを取得したい場合に設定します。
( 動作未検証です。)
> set HTTP_FORWARDED_COUNT=1
[Meteor.onConnection] (http://docs.meteor.com/#/full/meteor_onconnection)
Set HTTP_FORWARDED_COUNT to an integer representing the number of proxies in front of your server. For example, you'd set it to "1" when your server was behind one proxy.
MAIL_URL
アプリケーションからメールを送信するにはMAIL_URL
環境変数にsmtpサーバーを指定します。
> set MAIL_URL=smtp://your_email:password@smtp.gmail.com:25/
[Email.send] (http://docs.meteor.com/#/full/email_send)
The server reads from the MAIL_URL environment variable to determine how to send mail.
the MAIL_URL environment variable should be of the form smtp://USERNAME:PASSWORD@HOST:PORT/.
メールを送るためにemailパッケージを追加します。
> meteor add email
Changes to your project's package version selections:
email added, version 1.0.8
email: Send email messages
メールの送信はEmail APIを使用します。
Email.send({
to: to,
from: from,
subject: subject,
text: text
});
NODE_ENV
nodejsの実行環境の切り替えをNODE_ENV
環境変数で指定します。
> set NODE_ENV=production
> set NODE_ENV=development
NODE_OPTIONS
History.md
v0.5.3, 2013-Jan-07The NODE_OPTIONS environment variable can be used to pass command-line flags to node (eg, --debug or --debug-brk to enable the debugger).
> set NODE_OPTIONS=--debug-brk
[Command line] (http://docs.meteor.com/#/full/commandline)
To pass additional options to Node.js use the NODE_OPTIONS environment variable. For example: NODE_OPTIONS='--debug' or NODE_OPTIONS='--debug-brk'
[Node Inspector] (https://github.com/node-inspector/node-inspector)
> npm install -g node-inspector
> node-inspector
Node Inspector v0.12.3
Visit http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858 to start debugging.
Meteor 1.0以降は下記のdebugおよびshellコマンドでデバッグを行うことができます。
> meteor debug
> meteor shell
DDP_DEFAULT_CONNECTION_URL
DDP analyzerでserver/clientのメッセージをモニタリングする場合に指定するURLをDDP_DEFAULT_CONNECTION_URL
環境変数に設定します。
> set DDP_DEFAULT_CONNECTION_URL=http://localhost:3030
[Introduction to DDP] (https://meteorhacks.com/introduction-to-ddp)
DDP is the heart of MeteorJS and it’s the protocol Meteor uses to communicate between the client and the server.
DDP is an acronym for Distributed Data Protocol.
[Discover Meteor DDP in Realtime] (https://meteorhacks.com/discover-meteor-ddp-in-realtime)
DDP is the protocol Meteor uses to communicate between client and the sever.
It’s a very simple and tiny protocol (learn DDP). But it’s somewhat tough to look at DDP messages being generated while you’re using your app.
[Meteor DDP Analyzer] (https://github.com/arunoda/meteor-ddp-analyzer)
> npm install -g ddp-analyzer
> ddp-analyzer-proxy
DDP Proxy Started on port: 3030
===============================
Export following env. variables and start your meteor app
export DDP_DEFAULT_CONNECTION_URL=http://localhost:3030
meteor
DISABLE_WEBSOCKETS
Websocketsを使用しないよう設定することができます。
( 動作未検証です。)
History.md
v0.6.4, 2013-Jun-10If you set the DISABLE_WEBSOCKETS environment variable, browsers will not attempt to connect to your app using Websockets.
> set DISABLE_WEBSOCKETS=1
[Websockets] (http://www.meteorpedia.com/read/Websockets)
It's not documented, but you can disable websockets with the following environment variable
参照箇所のソースコード(抜粋)
// If you know your server environment (eg, proxies) will prevent websockets
// from ever working, set $DISABLE_WEBSOCKETS and SockJS clients (ie,
// browsers) will not waste time attempting to use them.
// (Your server will still have a /websocket endpoint.)
if (process.env.DISABLE_WEBSOCKETS) {
serverOptions.websocket = false;
} else {
serverOptions.faye_server_options = {
extensions: websocketExtensions()
};
}
MONGO_URL
MongoDBのデータベースに接続するURLをMONGO_URL
環境変数で指定します。
> set MONGO_URL=mongodb://localhost:27017/db_name
ユーザー認証が必要な場合
> set MONGO_URL=mongodb://user:password@localhost:27017/db_name
レプリケーション環境では下記のようにカンマ区切りで指定します。
下記は同一ホストに3つのMongoDBインスタンスを立ち上げている場合の例です。
> set MONGO_URL=mongodb://user:password@localhost:30001,localhost:30002,localhost:30003/db_name
MONGO_OPLOG_URL
MongoDBのOPLOGを格納するデータベースに接続するURLをMONGO_OPLOG_URL
環境変数で指定します。
( 動作未検証です。)
History.md
v0.7.0, 2013-Dec-17Oplog tailing is automatically enabled in development mode with meteor run, and can be enabled in production with the MONGO_OPLOG_URL environment variable.
oplogを保存しているlocalデータベースを参照できる専用のユーザーを追加します。
cluster:PRIMARY> db.createUser({user: "oplogger", pwd: "oplogpass", roles: [{role: "read", db: "local"}]})
> set MONGO_OPLOG_URL=mongodb://oplogger:oplogpass@localhost:30001,localhost:30002,localhost:30003/local?authSource=admin
[Oplog Observe Driver] (https://github.com/meteor/meteor/wiki/Oplog-Observe-Driver)
Oplog tailing is automatically enabled in development mode with meteor run, and can be enabled in production with the MONGO_OPLOG_URL environment variable.
参照箇所のソースコード(抜粋)
// Create the singleton RemoteCollectionDriver only on demand, so we
// only require Mongo configuration if it's actually used (eg, not if
// you're only trying to receive data from a remote DDP server.)
MongoInternals.defaultRemoteCollectionDriver = _.once(function () {
var connectionOptions = {};
var mongoUrl = process.env.MONGO_URL;
if (process.env.MONGO_OPLOG_URL) {
connectionOptions.oplogUrl = process.env.MONGO_OPLOG_URL;
}
if (! mongoUrl)
throw new Error("MONGO_URL must be set in environment");
return new MongoInternals.RemoteCollectionDriver(mongoUrl, connectionOptions);
});
OPLOG_URL
MeteorのSmart Collectionsというパッケージを使用する場合に設定する環境変数のようです。このパッケージは現在"This is a archived project"という状態です。
( 動作未検証です。)
[Meteor Smart Collections] (https://github.com/arunoda/meteor-smart-collections)
Smart Collection is now retired & Meteor's Collection implementation has fixes for most of the performance bottlenecks.
METEOR_WATCH_FORCE_POLLING
Meteorがファイルの変更を検知する間隔を変更することができます。間隔は後述するMETEOR_WATCH_POLLING_INTERVAL_MS
環境変数で指定します。
通常、この設定は不要ですが、NFSやVagrantの共有フォルダを使用している場合などファイルシステムがファイル変更の検知をサポートしていない場合に使用するようです。
( 動作未検証です。)
History.md
v1.0.2, 2014-Dec-19On file systems that do not support these events (NFS, Vagrant Virtualbox shared folders, etc), file changes will only be detected every 5 seconds; to detect changes more often in these cases (but use more CPU), set the METEOR_WATCH_FORCE_POLLING environment variable.
> set METEOR_WATCH_FORCE_POLLING=1
METEOR_WATCH_POLLING_INTERVAL_MS
- [File Change Watcher Efficiency] (https://github.com/meteor/meteor/wiki/File-Change-Watcher-Efficiency)
> set METEOR_WATCH_POLLING_INTERVAL_MS=500
参照箇所のソースコード(抜粋)
// Set METEOR_WATCH_FORCE_POLLING environment variable to a truthy value to
// force the use of files.watchFile instead of pathwatcher.watch.
// Enabled on Mac and Linux and disabled on Windows by default.
var PATHWATCHER_ENABLED = !process.env.METEOR_WATCH_FORCE_POLLING;
if (process.platform === "win32") {
PATHWATCHER_ENABLED = false;
}
var DEFAULT_POLLING_INTERVAL =
~~process.env.METEOR_WATCH_POLLING_INTERVAL_MS || 5000;
var NO_PATHWATCHER_POLLING_INTERVAL =
~~process.env.METEOR_WATCH_POLLING_INTERVAL_MS || 500;
HTTP_PROXY / HTTPS_PROXY
[Using Meteor behind a proxy] (https://github.com/meteor/meteor/wiki/Using-Meteor-behind-a-proxy)
Like a lot of other command-line software, the Meteor tool reads the proxy configuration from the HTTP_PROXY and HTTPS_PROXY environment variables (the lower case variants work, too).
METEOR_OFFLINE_CATALOG
パッケージカタログ(と呼ばれるデータベース)の更新を行わないように指定します。
( 動作未検証です。)
> set METEOR_OFFLINE_CATALOG=1
参照箇所のソースコード(抜粋)
// Initialize the server catalog. Among other things, this is where we get
// release information (used by springboarding). We do not at this point talk
// to the server and refresh it.
catalog.official.initialize({
offline: !!process.env.METEOR_OFFLINE_CATALOG
});
METEOR_PROFILE
アプリケーションのビルドにかかる時間を計測します。METEOR_PROFILE
環境変数には閾値をミリ秒で指定します。
デフォルトは100ミリ秒で、ビルドに100ミリ秒以上かかった項目が計上されます。
- [Measure meteor build time] (https://forums.meteor.com/t/measure-meteor-build-time/3656)
> set METEOR_PROFILE=50
参照箇所のソースコード(抜粋)
// Tiny profiler
//
// Enable by setting the environment variable `METEOR_PROFILE`.
var enabled = !!process.env['METEOR_PROFILE'];
var filter = ~ ~process.env['METEOR_PROFILE'] || 100; // ms
METEOR_LOG
METEOR_LOG
環境変数に"debug"と指定すると標準出力にデバッグログが出力されます。
> set METEOR_LOG=debug
参照箇所のソースコード(抜粋)
self._logThreshold = LEVEL_CODE_INFO;
var logspec = process.env.METEOR_LOG;
if (logspec) {
logspec = logspec.trim().toLowerCase();
if (logspec == 'debug') {
self._logThreshold = LEVEL_CODE_DEBUG;
}
}
METEOR_PRINT_CONSTRAINT_SOLVER_INPUT
デバッグ用の設定のようです。
( 動作未検証です。)
History.md
v1.1, 2015-Mar-31Setting the METEOR_PRINT_CONSTRAINT_SOLVER_INPUT environment variable prints information useful for diagnosing constraint solver bugs.
> set METEOR_PRINT_CONSTRAINT_SOLVER_INPUT=1
参照箇所のソースコード(抜粋)
if (Meteor.isServer &&
process.env['METEOR_PRINT_CONSTRAINT_SOLVER_INPUT']) {
console.log("CONSTRAINT_SOLVER_INPUT = ");
console.log(JSON.stringify(input.toJSONable(), null, 2));
}
USE_JSESSIONID
スティッキーセッション機能のためにJSESSIONIDクッキーを有効にします。
( 動作未検証です。)
History.md
v0.6.6, 2013-Oct-10Add support for JSESSIONID cookies for sticky sessions. Set the USE_JSESSIONID environment variable to enable placing a JSESSIONID cookie on sockjs requests.
> set USE_JSESSIONID=1
参照箇所のソースコード(抜粋)
// Set the USE_JSESSIONID environment variable to enable setting the
// JSESSIONID cookie. This is useful for setting up proxies with
// session affinity.
jsessionid: !!process.env.USE_JSESSIONID