Skip to content

Instantly share code, notes, and snippets.

@bajtos
Last active August 29, 2015 14:08
Show Gist options
  • Save bajtos/65ef3a6a31c03878be72 to your computer and use it in GitHub Desktop.
Save bajtos/65ef3a6a31c03878be72 to your computer and use it in GitHub Desktop.
express and phases
function createLoopBackApp() {
var app = express();
// add loopback stuff
app.phase('routes').use(function(req, res, next) {
if (app._router) {
app._router.handle(res, res, next);
} else {
next();
}
}
}
app.handle = function(req, res, next) {
done = done || this.createFinalHandler();
// run our LoopBack's custom phase code
this._phases.run({ req: req, res: res }, done);
}
app.handle = function(req, res, done) {
var router = this._router;
// final handler
done = done || this.createFinalHandler();
// no routes
if (!router) {
debug('no routes defined on app');
done();
return;
}
router.handle(req, res, done);
};
app.createFinalHandler = function() {
return finalhandler(req, res, {
env: this.get('env'),
onerror: logerror.bind(this)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment