Demo entry 2780254

loader.js

   

Submitted by Esau Garcia on Sep 29, 2015 at 23:05
Language: JavaScript. Code size: 2.5 kB.

module.exports = function (_imports) {

	/*
	 * Get the imports.
	 */
	var async	  = _imports.async,
		fs		  = _imports.fs,
		path	  = _imports.path,

		benchmark = _imports.benchmark,
		green	  = _imports.green,
		log		  = _imports.log,
		magenta	  = _imports.magenta,
		yellow	  = _imports.yellow,

		_root	  = _imports._root,
		_settings = _imports._settings,

		_files	  = {
			"bodyparser"		  : "body-parser",
			"consolidate"		  : "consolidate",
			"compression"		  : "compression",
			"crypto"			  : "crypto",
			"errorhandler"		  : "errorhandler",
			"express"			  : "express",
			"expresscoffee"		  : "coffee-middleware",
			"expressless"		  : "express-less",
			"expressforcessl"	  : "express-force-ssl",
			"expresssession"	  : "express-session",
			"expresssocketsession": "express-socket.io-session",
			"servefavicon"		  : "serve-favicon",
			"geocoder"			  : "geocoder",
			"http"				  : "http",
			"https"				  : "https",
			"ioredis"			  : "ioredis",
			"ip"				  : "ip",
			"jade"				  : "jade",
			"jsonwebtoken"		  : "jsonwebtoken",
			"lodash"			  : "lodash",
			"mailgun"			  : "mailgun",
			"methodoverride"	  : "method-override",
			"mime"				  : "mime",
			"morgan"			  : "morgan",
			"multer"			  : "multer",
			"path"				  : "path",
			"peer"				  : "peer",
			"process"			  : "process",
			"sessionfilestore"	  : "session-file-store",
			"socketio"			  : "socket.io",
			"underscore"		  : "underscore",
			"url"				  : "url"
		},

		_tasks = [],
		_loadModule = function (key, value) {
			_tasks.push(function (done) {
				log(green("Loaded module " + value + " ✔", 2));
				_imports[key] = require(value);
				done();
			});
		},
		_name,
		_time;

	log(yellow("Preparing modules.", 1));
	for (_name in _files) {
		if (_files.hasOwnProperty(_name)) {
			_loadModule(_name, _files[_name]);
		}
	}

	/*
	 * Import SSL files.
	 */
	_imports.key  = fs.readFileSync( path.join(_root, _settings.ssl.key) );
	_imports.cert = fs.readFileSync( path.join(_root, _settings.ssl.cert) );
	_imports.ca	  = fs.readFileSync( path.join(_root, _settings.ssl.ca) );

	log(yellow("Loading all modules in parallel:", 1));
	async.parallel(_tasks, function () {
		_time = benchmark.get("loader");
		_imports.benchmarks.loader = _time;
		log(magenta("Execution took " + _time + "ms."));
		benchmark.set("redis");
		log(yellow("Executing Redis client:"));
		require("./redis")(_imports);
	});

};

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).