mimeware
v0.1.2
Published
Framework agnostic HTTP middleware to infer the proper MIME content type response header
Downloads
242
Maintainers
Readme
mimeware
Node.js/io.js HTTP server middleware to infer and define the proper MIME content type as response header
It is web framework agnostic and works properly in Connect, Express, Restify, Sails... among others
which implements the standard connect-based middleware interface: use(function (req, res, next) { ... })
It includes all 600+ types and 800+ extensions defined by the Apache project, plus additional types submitted by the node.js community. It uses node-mime
It was implemented specially for older Express/Connect versions which has no smart support for content type discovering
Installation
npm install mimeware --save
Usage
var express = require('express')
var mimeware = require('mimeware')
var app = express()
app.use(mimeware({ defaultType: 'text/html' }))
app.get('/hello', function (req, res, next) {
// respond with default type: text/html
res.send('Hello World!')
})
app.get('/hello.json', function (req, res, next) {
// respond with type: application/json
res.json({ say: 'Hello World!' })
})
app.get('/hello.xml', function (req, res, next) {
// respond with type: text/xml
res.send('<say>Hello World!</say>')
})
Options
defaultType
Type: string
Type: text/html
Define the default MIME type to use if cannot infer it
ignore
Type: array<string|regex>
An array of regex or string-like path patterns to ignore
defaultCharset
Type: string
Default: utf-8
Define the default charset encoding type if cannot infer one.
charset
Type: boolean
Default: true
Define the proper encoding charset if required
License
MIT © Tomas Aparicio