mirror of
/repos/Prototyper.git
synced 2025-12-30 06:31:32 +01:00
use express content-type helper
This commit is contained in:
parent
3ecc74fa9a
commit
6861dd5ecc
@ -1,21 +1,10 @@
|
||||
var mimetypes = {
|
||||
'js': 'application/javascript',
|
||||
'html': 'text/html',
|
||||
'md': 'text/html',
|
||||
'text': 'text/plain',
|
||||
'css': 'text/css',
|
||||
'less': 'text/css'
|
||||
};
|
||||
|
||||
var getMimeType = function (ext) {
|
||||
if (mimetypes[ext]) {
|
||||
return mimetypes[ext];
|
||||
}
|
||||
|
||||
return mimetypes.text;
|
||||
};
|
||||
|
||||
/*
|
||||
* 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);
|
||||
@ -24,12 +13,12 @@ module.exports = function (options, res, next) {
|
||||
}
|
||||
return next(err);
|
||||
}
|
||||
var contentType = getMimeType(options.ext);
|
||||
res.setHeader('Content-Type', contentType);
|
||||
var content = result;
|
||||
if (options.attribute) {
|
||||
content = result[options.attribute];
|
||||
}
|
||||
// Set _Content-Type_ response header with `type` through `mime.lookup()`
|
||||
res.type(options.ext);
|
||||
return res.send(content);
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user