Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

woodland

Package Overview
Dependencies
Maintainers
1
Versions
352
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

woodland

Lightweight HTTP/HTTPS router with virtual hosts

  • 1.0.14
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
383
increased by609.26%
Maintainers
1
Weekly downloads
 
Created
Source

woodland

build status

Lightweight HTTP/HTTPS router with virtual hosts. Sets an accurate Allow header based on routes.

Example

"use strict";

const http = require("http");
let router = require("woodland")({defaultHeaders: {"Cache-Control": "no-cache"}});

router.use("/", (req, res) => {
	res.writeHead(200, {"Content-Type": "text/plain"});
	res.end("Hello World!");
});

http.createServer(router.route).listen(8000);

Event Handlers

onclose (req, res)

Executes if the connection was terminated before res.end() was called or able to flush.

onerror (req, res, err)

Executes if the request cannot be routed, default handler sends a basic text response.

onfinish (req, res)

Executes after the response has been sent.

API

woodland ({cacheSize: 1000, defaultHeaders: {}, defaultHost: "localhost", hosts: ["localhost"], seed: random})

Returns a woodland router.

allowed (method, uri, host, override = false)

Calls routes() and returns a Boolean to indicate if method is allowed for uri.

allows (uri, host, override = false)

Returns a String for the Allow header. Caches value, & will update cache if override is true.

blacklist (fn)

Blacklists fn for calculating the return of allows().

decorate (req, res)

Decorates allow, body, ip, parsed, query, & host on req and header() & locals{} on res.

hash (arg)

Returns a murmur3hash of arg.

host (arg)

Determines the host for arg.

route (req, res)

Function for http.createServer() or https.createServer().

routes (uri, host, method, override = false)

Returns an Array of middleware for the request. Caches value, & will update cache if override is true.

setHost (arg)

Registers a virtual host with the woodland.

use (path, fn, method = "GET", host = "all")

Registers middleware for a route. path is a regular expression, and if not passed it defaults to /.*. method can be all if you want the middleware to be used for all HTTP methods.

url (req)

Constructs a full URL from req.

License

Copyright (c) 2016 Jason Mulligan Licensed under the BSD-3 license.

Keywords

FAQs

Package last updated on 01 Jul 2016

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