Skip to content

Commit

Permalink
Allow plugins to leverage PB dependencies as a fallback. Whitespace c…
Browse files Browse the repository at this point in the history
…leanup elsewhere.
  • Loading branch information
brianhyder committed Jan 18, 2016
1 parent 39c724d commit 597742c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
30 changes: 15 additions & 15 deletions include/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var winston = require('winston');
function Configuration(){}

/**
*
*
* @static
* @readonly
* @property DOCUMENT_ROOT
Expand All @@ -46,7 +46,7 @@ function Configuration(){}
Configuration.DOCUMENT_ROOT = __dirname.substr(0, __dirname.indexOf(path.sep+'include'));

/**
*
*
* @static
* @readonly
* @property EXTERNAL_ROOT
Expand Down Expand Up @@ -76,7 +76,7 @@ var LOG_DIR = path.join(Configuration.DOCUMENT_ROOT, 'log');
var LOG_FILE = path.join(LOG_DIR, 'pencilblue.log');

/**
* The configuration module overrides file name
* The configuration module overrides file name
* @private
* @static
* @readonly
Expand All @@ -98,7 +98,7 @@ var OVERRIDE_FILE_PATHS = [
path.join(Configuration.EXTERNAL_ROOT, CONFIG_MODULE_NAME)
];

/**
/**
* Retrieve the base configuration
*/
Configuration.getBaseConfig = function(multisite) {
Expand Down Expand Up @@ -141,9 +141,9 @@ Configuration.getBaseConfig = function(multisite) {

//the name of the default DB for the system
name: 'pencil_blue',

options: {

//http://docs.mongodb.org/manual/core/write-concern/
w: 1
},
Expand Down Expand Up @@ -252,9 +252,9 @@ Configuration.getBaseConfig = function(multisite) {
//values will not be purged from memory once expired.
memory_timeout: 0
},
//The default plugin. Allows for the default plugin to be
//referenced from a single location. The property can be overriden

//The default plugin. Allows for the default plugin to be
//referenced from a single location. The property can be overriden
//but may have unexpected behavior.
default: 'pencilblue'
},
Expand Down Expand Up @@ -321,9 +321,9 @@ Configuration.getBaseConfig = function(multisite) {
use_handoff_port_in_redirect: false,
key: "ssl/key.pem",
cert: "ssl/cert.crt",
//The certificate authority, or chain, is optional. It is
//recommended to keep the paths consistent and place the CA cert

//The certificate authority, or chain, is optional. It is
//recommended to keep the paths consistent and place the CA cert
//at: "ssl/chain.crt"
chain: null
},
Expand Down Expand Up @@ -454,12 +454,12 @@ Configuration.load = function(filePaths) {
};

/**
*
*
* @static
* @method mergeWithBase
*/
Configuration.mergeWithBase = function(overrides) {

var multisite = overrides && overrides.multisite ? overrides.multisite.enabled : false;
var baseConfig = Configuration.getBaseConfig(multisite);

Expand All @@ -475,7 +475,7 @@ Configuration.mergeWithBase = function(overrides) {
if (config.media.urlRoot.lastIndexOf('/') === (config.media.urlRoot.length - 1)) {
config.media.urlRoot = config.media.urlRoot.substring(0, config.media.urlRoot.length - 1);
}

return config;
};

Expand Down
16 changes: 8 additions & 8 deletions include/http/server_initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var fs = require('fs');
function ServerInitializer(/*pb*/) {}

/**
* Initializes the server. Depending on the configuration will start an HTTP
* Initializes the server. Depending on the configuration will start an HTTP
* server and/or an HTTPs server.
* @param {Object} context
* @param {Logger} context.log
Expand Down Expand Up @@ -94,7 +94,7 @@ ServerInitializer.prototype.initHttp = function(context, cb) {
ServerInitializer.prototype.initHttps = function(context, cb) {
var log = context.log;
var config = context.config;

//create the server with options & callback
var server = this.getSslServer(context);

Expand All @@ -103,17 +103,17 @@ ServerInitializer.prototype.initHttps = function(context, cb) {

var self = this;
var tasks = [

//start primary HTTPS server
function (callback) {
log.info('ServerInitializer: HTTPS server starting, binding on IP %s and port: %d', config.siteIP, config.sitePort);
this.startServer(server, config.sitePort, config.siteIP, callback);
self.startServer(server, config.sitePort, config.siteIP, callback);
},

//start handoff server that will force redirect back to HTTPs
function (callback) {
log.info('ServerInitializer: Handoff HTTP server starting, binding on IP %s and port: %d', config.server.ssl.handoff_ip, config.server.ssl.handoff_port);
this.startServer(handOffServer, config.server.ssl.handoff_port, config.server.ssl.handoff_ip, callback);
self.startServer(handOffServer, config.server.ssl.handoff_port, config.server.ssl.handoff_ip, callback);
},
];
async.series(tasks, function(err){
Expand Down Expand Up @@ -161,8 +161,8 @@ ServerInitializer.prototype.getSslServerOptions = function(config) {
key: fs.readFileSync(config.server.ssl.key),
cert: fs.readFileSync(config.server.ssl.cert),
};
//the certificate authority or "chain" is optional. Needed for

//the certificate authority or "chain" is optional. Needed for
//self-signed certs
var chainPath = config.server.ssl.chain;
if (util.isString(chainPath)) {
Expand Down
12 changes: 10 additions & 2 deletions include/service/entities/plugin_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -1503,8 +1503,16 @@ module.exports = function PluginServiceModule(pb) {
* @return {*} The entity returned by the "require" call.
*/
PluginService.require = function(pluginDirName, moduleName) {
var modulePath = path.join(PluginService.getPluginsDir(), pluginDirName, 'node_modules', moduleName);
return require(modulePath);
var modulePath = null;
try {
modulePath = path.join(PluginService.getPluginsDir(), pluginDirName, 'node_modules', moduleName);
return require(modulePath);
}
catch(e) {
pb.log.warn('PluginService:%s Failed to find module %s at path %s. Attempting to retrieve from PB context', pluginDirName, moduleName, modulePath)
pb.log.debug(e.stack);
}
return require(moduleName);
};

/**
Expand Down

0 comments on commit 597742c

Please sign in to comment.