• Jump To … +
    ClientController.js ClientRequest.js ExpressServerRequest.js ReactServerAgent.js Cache.js Plugins.js Request.js handlePage.js loggingClient.js ClientRequestSpec.js NormalValuesPage.js NullValuePromisesPage.js NullValuesPage.js reactMiddlewareSpec.js client.js common.js History.js RootContainer.js RootElement.js TheFold.js config.js constants.js Navigator.js RequestContext.js logging.js client.js common.js response.js server.js stats.js renderMiddleware.js server.js ClientCssHelper.js DebugUtil.js PageUtil.js RequestLocalStorage.js StringEscapeUtil.js bundleNameUtil.js navigateTo.js
  • config.js

  • ¶
    /**
     * Thin wrapper around the environment-specific configuration file
     */
    
    var config = null;
    
    if (SERVER_SIDE) {
    
    	module.exports = function () {
  • ¶

    only read out the config once, and then cache it. -sra.

    		if (null === config) {
  • ¶

    eslint-disable-next-line no-process-env

    			if (process.env.REACT_SERVER_CONFIGS) {
    				var path = require('path');
  • ¶

    eslint-disable-next-line no-process-env

    				var configFilePath = process.env.REACT_SERVER_CONFIGS;
  • ¶

    Node.js tries to load config.js file first. If config.js doesn’t exist, Node.js then try to load config.json.

    If configFilePath is absolute require.resolve will reset to it, correctly overriding process.cwd(). If it is relative, then it will be relative to process.cwd().

    				configFilePath = path.resolve(process.cwd(), configFilePath, "config");
    				config = Object.freeze(require(configFilePath));
    			} else {
    				config = Object.freeze({});
    			}
    		}
    		return config;
    	};
    
    } else {
  • ¶

    I’m not entirely clear why this code is here; it seems to just copy all the key & values from inputEnv; I’m not clear why the client wouldn’t just use inputEnv.

    	var env = {
    
    		rehydrate: function (inputEnv) {
    			Object.keys(inputEnv).forEach( key => {
    				env[key] = inputEnv[key];
    			});
  • ¶

    janky: remove the ‘rehydrate’ method from the environment module after it’s used

    			delete env.rehydrate;
    		},
    	};
    
    	module.exports = function () {
    		return env;
    	};
    }