Last active
August 29, 2015 14:08
-
-
Save bajtos/65ef3a6a31c03878be72 to your computer and use it in GitHub Desktop.
express and phases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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