Skip to content

Instantly share code, notes, and snippets.

@ndhoule
Last active September 6, 2018 16:36
Show Gist options
  • Save ndhoule/9028677 to your computer and use it in GitHub Desktop.
Save ndhoule/9028677 to your computer and use it in GitHub Desktop.
Trying to mount an Express app in Sails.js
'use strict';
var kue = require('kue');
var util = require('sails-util');
var ConfigurationError = function(message) {
this.name = 'ConfigurationError';
this.message = message || '';
};
ConfigurationError.prototype = Error.prototype;
module.exports = function(sails) {
return {
defaults: {
queue: {
redis: {
port: 6379,
host: '127.0.0.1',
options: {}
}
}
},
configuration: function(cb) {
if (!sails.config.queue) {
throw new ConfigurationError('No Kue configuration found!');
}
if (!util.isObject(sails.config.queue)) {
throw new ConfigurationError([
'Invalid custom queue settings!',
'',
'Basic usage:',
'{ prefix: \'your prefix\' }'
].join('\n'));
}
if (!isString(sails.config.queue.prefix)) {
throw new ConfigurationError([
'Invalid custom queue settings!',
'`prefix` option must be a string.'
].join('\n'));
}
cb();
},
initialize: function(cb) {
sails.queue = kue.createQueue({
redis: sails.config.queue.redis
});
// I've tried a few things here, but can't seem to get this to work.
// I'm sure this is the incorrect event to be listening on, too.
// Ideally, what I want is to mount this app via the router so I can
// apply policies, etc. to it.
sails.on('ready', function() {
sails.hooks.http.app.use(kue.app);
});
cb();
}
};
};
'use strict';
var passport = require('passport');
/**
* Configure advanced options for the Express server inside of Sails.
*
* For more information on configuration, check out:
* http://sailsjs.org/#documentation
*/
module.exports.express = {
middleware: {
custom: true
},
customMiddleware: function(app) {
app.use(passport.initialize());
app.use(passport.session());
// TODO: This should be worked into the Kue hook and password protected.
// Ideally, we'd mount this with Sails' router so that we can apply policies
// to it, obviating the need for something like simple auth.
app.use('/admin/queue', require('kue').app);
}
};
@anabelle
Copy link

Did you manage to get kue mounted on sails? how?

@kithokit
Copy link

kithokit commented Aug 1, 2014

I would like to know too

@sudipta26889
Copy link

Me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment