mimeware

0.1.2 • Public • Published

mimeware Build Status Dependency Status NPM version

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

Package Sidebar

Install

npm i mimeware

Weekly Downloads

33

Version

0.1.2

License

MIT

Last publish

Collaborators

  • h2non