Skip to content

Instantly share code, notes, and snippets.

@floatdrop
Last active August 29, 2015 14:24
Show Gist options
  • Save floatdrop/a5f4cc79d160d0f09a87 to your computer and use it in GitHub Desktop.
Save floatdrop/a5f4cc79d160d0f09a87 to your computer and use it in GitHub Desktop.
Refactoring Tools!
// Disclaimer: пример намеренно упрощен
var app = express();
app.get('/user/:id', function (req, res, next) {
if (req.params.id === '31337') {
res.send('Hello eleet!');
return;
}
res.send('Hello user!');
});
// After refactoring
var app = express();
function validate(req, res, next) {
if (req.params.id === '31337') {
res.send('Hello eleet!');
return;
}
}
app.get('/user/:id', function (req, res, next) {
validate(req, res, next);
res.send('Hello user!'); // BOOM! 2 часа искали в коде
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment