Socket
Book a DemoInstallSign in
Socket

routil-mediatypes

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

routil-mediatypes

handle multiple media types

latest
Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

routil-mediatypes build status

handle multiple media types

Example

var http = require("http")
    , mediaTypes = require("routil-mediatypes")()

http.createServer(function (req, res) {
    mediaTypes(req, res, {
        "application/json": sendJson
        , "text/html": sendHtml
    })(res)
}).listen(8080)

function sendJson(res) { res.end("json") }

function sendHtml(res) { res.end("html") }

Example with custom error handling

var http = require("http")
    , mediaTypes = require("routil-mediatypes")({
        errorPage: function (req, res) {
            return function (error, statusCode) {
                res.statusCode = statusCode
                res.end("error :(", err.message)
            }
        }
    })

http.createServer(function (req, res) {
    mediaTypes(req, res, {
        "application/json": sendJson
        , "text/html": sendHtml
    })(res)
}).listen(8080)

function sendJson(res) { res.end("json") }

function sendHtml(res) { res.end("html") }

Example with custom error page

var ErrorPage = require("error-page")
    , partialRight = require("ap").partialRight
    , errorPageOptions = { ... }
    , errorPage = partialRight(ErrorPage, errorPageOptions)
    , mediaTypes = require("routil-mediatypes")({
        errorPage: errorPage
    })

...

Installation

npm install routil-mediaTypes

Tests

make test

Contributors

  • Raynos

MIT Licenced

FAQs

Package last updated on 17 Jul 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts