これを修正するには2つの方法があると思います。
単純なミドルウェアを使用する
app.get('*.webapp', function (req, res, next) {
res.header('Content-Type', 'application/x-web-app-manifest+json');
next();
});
モンキーパッチ
応答オブジェクトを変更し、setHeader
メソッドを上書きします。ここで、応答を実際の値に変更できます(ミドルウェアとして機能します)。
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) {
// you can be 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'));
したがって、バンドルされているモジュールの代わりに、独自のmimeモジュールを使用します。
静的ミドルウェアの更新req.contentType
はこのメソッドを使用していません。