From 6861dd5ecc2db0f452fadf6b6db7381c67cd30b0 Mon Sep 17 00:00:00 2001 From: Aiko Mastboom Date: Mon, 13 May 2013 21:05:19 +0200 Subject: [PATCH] use express content-type helper --- lib/responder.js | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/lib/responder.js b/lib/responder.js index 83eb877..2c6d965 100644 --- a/lib/responder.js +++ b/lib/responder.js @@ -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); }; };