Skip to content

Commit

Permalink
Allow session adapter to be required directly (still supporting `adap…
Browse files Browse the repository at this point in the history
…ter` being a string naming the adapter to be required).
  • Loading branch information
sgress454 committed Nov 21, 2016
1 parent b5db053 commit 039d245
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/hooks/session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,22 @@ module.exports = function(app) {
// or catch and return error:
else {

var SessionAdapter;
var SessionAdapter, CustomStore;
try {
// If `sails.config.session.adapter` is a string, attempt to require the
// modulde identified by the string.
if (_.isString(app.config.session.adapter)) {
SessionAdapter = require(path.resolve(app.config.appPath, 'node_modules', app.config.session.adapter));
}
// Otherwise if it's an object (including a function!), set SessionAdapter to that value.
else if (_.isObject(app.config.session.adapter)) {
SessionAdapter = app.config.session.adapter;
}
// Otherwise bail, because sails.config.session.adapter is invalid.
else {
return cb(new Error('If configured, `sails.config.session.adapter` should be a reference to an Express session adapter! Instead got `' + util.inspect(app.config.session.adapter)));
}
// Attempt to initialize the adapter using the express-session module
SessionAdapter = require(path.resolve(app.config.appPath, 'node_modules', sessionConfig.adapter));
try {
var CustomStore = SessionAdapter(require('express-session'));
sessionConfig.store = new CustomStore(sessionConfig);
Expand Down

0 comments on commit 039d245

Please sign in to comment.