Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc