1
0
mirror of /repos/Prototyper.git synced 2025-12-30 06:31:32 +01:00
Prototyper/lib/responder.js
2014-12-30 13:51:07 +01:00

30 lines
678 B
JavaScript

/*
* options.ext: determines content-type
* options.attribute: sends result[options.attribute] in stead of result
*/
module.exports = function (options, res, next) {
"use strict";
return function responder(err, result) {
if (err) {
console.log('ERR responder', options, err);
if (/Data not found*/.test(err.message)) {
res.status(404);
}
return next(err);
}
var content = result;
if (options.attribute) {
content = result[options.attribute];
}
if (options.ext) {
// Set _Content-Type_ response header with `type` through `mime.lookup()`
res.type(options.ext);
} else {
res.type('text/plain');
}
return res.send(content);
};
};