express - Access bundled node.js module -
i wrote small express.js based web app. serve manifest.webapp express.js doesn't send correct mime type. because express.js bundles mime module require("mime").define(...)
has no effect. defines mime type wrong module!
is there way access mime module bundled express.js? or there way tell npm (and nodejitsu) not use bundled modules of express.js?
i think there 2 ways fix this.
use simple middleware
app.get('*.webapp', function (req, res, next) { res.header('content-type', 'application/x-web-app-manifest+json'); next(); });
monkey patching
modify response object , overwrite setheader
method, can modify response actual value (it work middleware).
var mime = require('mime'); mime.define({ 'application/x-web-app-manifest+json': [ 'webapp' ] }); app.use(function (req, res, next) { var setheader = res.setheader; res.setheader = function (field, val) { // can more strict here if (field === 'content-type') { val = mime.lookup(req.path); } return setheader.call(this, field, val); } next(); }); app.use(express.static(__dirname + 'your-static-dir'));
so you'll use own mime module instead of bundled one.
update static middleware not using req.contenttype
method.
Comments
Post a Comment