Propagate meteorEnv subset of process.env from server to client.

Fixes #6399.
This commit is contained in:
Ben Newman
2016-03-08 17:33:05 -05:00
parent 93e5e7391f
commit 40857bdaff
17 changed files with 37 additions and 27 deletions

View File

@@ -0,0 +1 @@
meteorEnv = __meteor_runtime_config__.meteorEnv;

View File

@@ -1,3 +0,0 @@
meteorEnv = {
NODE_ENV: "development"
};

View File

@@ -8,6 +8,9 @@ Package.describe({
Package.onUse(function(api) {
api.use('meteor', { unordered: true });
api.addFiles('env.js');
api.export("meteorEnv");
api.addFiles('client.js', 'client');
api.addFiles('server.js', 'server');
api.export('meteorEnv');
});

View File

@@ -0,0 +1,3 @@
meteorEnv = {
NODE_ENV: process.env.NODE_ENV || "development"
};

View File

@@ -0,0 +1 @@
meteorEnv = __meteor_runtime_config__.meteorEnv;

View File

@@ -1,3 +0,0 @@
meteorEnv = {
NODE_ENV: "production"
};

View File

@@ -8,6 +8,9 @@ Package.describe({
Package.onUse(function(api) {
api.use('meteor', { unordered: true });
api.addFiles('env.js');
api.addFiles('client.js', 'client');
api.addFiles('server.js', 'server');
api.export("meteorEnv");
});

View File

@@ -0,0 +1,3 @@
meteorEnv = {
NODE_ENV: process.env.NODE_ENV || "production"
};

View File

@@ -17,7 +17,7 @@ Meteor = {
* @static
* @type {Boolean}
*/
isDevelopment: meteorEnv.NODE_ENV === "development",
isDevelopment: meteorEnv.NODE_ENV !== "production",
/**
* @summary Boolean variable. True if running in client environment.

View File

@@ -7,4 +7,4 @@
Meteor.isCordova = true;
Meteor.isProduction = meteorEnv.NODE_ENV === "production";
Meteor.isDevelopment = meteorEnv.NODE_ENV === "development";
Meteor.isDevelopment = meteorEnv.NODE_ENV !== "production";

View File

@@ -1,6 +1,6 @@
Meteor = {
isProduction: meteorEnv.NODE_ENV === "production",
isDevelopment: meteorEnv.NODE_ENV === "development",
isDevelopment: meteorEnv.NODE_ENV !== "production",
isClient: false,
isServer: true,
isCordova: false

View File

@@ -6,6 +6,7 @@ Package.describe({
});
Package.onUse(function(api) {
api.use("underscore");
api.use("modules-runtime");
api.mainModule("client.js", "client");
api.mainModule("server.js", "server");

View File

@@ -24,7 +24,4 @@ if (typeof process.env !== "object") {
process.env = {};
}
Object.keys(meteorEnv).forEach(function (key) {
process.env[key] = meteorEnv[key];
});
_.extend(process.env, meteorEnv);

View File

@@ -281,7 +281,8 @@ WebAppInternals.generateBoilerplateInstance = function (arch,
var runtimeConfig = _.extend(
_.clone(__meteor_runtime_config__),
additionalOptions.runtimeConfigOverrides || {}
additionalOptions.runtimeConfigOverrides || {},
{ meteorEnv }
);
var jsCssUrlRewriteHook = bundledJsCssUrlRewriteHook || function (url) {

View File

@@ -357,6 +357,19 @@ function doRunCommand(options) {
webArchs.push("web.cordova");
}
let nodeEnv = process.env.NODE_ENV;
if (options.production) {
// If options.production, make sure $NODE_ENV === "production".
process.env.NODE_ENV = "production";
} else if (nodeEnv) {
// If $NODE_ENV is set, override options.production according to that.
options.production = nodeEnv === "production";
} else {
// Otherwise make sure $NODE_ENV is set according to
// options.production.
process.env.NODE_ENV = "development";
}
var runAll = require('../runners/run-all.js');
return runAll.run({
projectContext: projectContext,

View File

@@ -200,8 +200,6 @@ _.extend(AppProcess.prototype, {
}
env.APP_ID = self.projectContext.appIdentifier;
// Display errors from (eg) the NPM connect module over the network.
env.NODE_ENV = 'development';
// We run the server behind our own proxy, so we need to increment
// the HTTP forwarded count.
env.HTTP_FORWARDED_COUNT =

View File

@@ -36,14 +36,6 @@ if (!process.env.APP_ID) {
process.env.APP_ID = configJson.appId;
}
// connect (and some other NPM modules) use $NODE_ENV to make some decisions;
// eg, if $NODE_ENV is not production, they send stack traces on error. connect
// considers 'development' to be the default mode, but that's less safe than
// assuming 'production' to be the default. If you really want development mode,
// set it in your wrapper script (eg, run-app.js).
if (!process.env.NODE_ENV)
process.env.NODE_ENV = 'production';
// Map from load path to its source map.
var parsedSourceMaps = {};