scratch-www/dev-server/handler.js

23 lines
404 B
JavaScript
Raw Normal View History

2018-01-30 09:53:25 -05:00
/**
* Constructor
*/
2018-01-30 09:53:25 -05:00
function Handler (route) {
// Handle redirects
if (route.redirect) {
2018-01-30 09:53:25 -05:00
return (req, res) => { res.redirect(route.redirect); };
}
2016-04-22 09:07:12 -04:00
var url = '/' + route.name + '.html';
return function (req, res, next) {
req.url = url;
next();
};
2018-01-30 09:53:25 -05:00
}
2018-01-30 09:53:25 -05:00
/**
* Export a new instance
*/
module.exports = function (route) {
return new Handler(route);
};