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

host-router

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

host-router

A simple HTTP host router

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Node HTTP host router

... does what it's called: It routes HTTP request by their host.

Features

  • Wildcards and Regular Expressions
  • Unmatching operator
  • WebSocket support (HTTPS comming later)
  • Full Express-integration (optional)

Example


var router = require("host-router"),
	express = require("express"),
	http = require("http");

// Raw function to handle request
function req(res, req) {
	res.end("Hello World from a function!");
}

// Express app
var app = express();
app.use("/", function(res, req, next) {
	res.send("This is express!");
});

// HTTP server
var server = http.createServer(function(res, req) {
	res.end("HTTP, ok?");
});

// Do routing
router({
	
	// Simple usage & function
	"foobar.com": req,

	// Wildcard & express
	".yolo.nl": app,

	// Regular Expression & HTTP server
	"/some-regexp/": server

},
80, // Port
"localhost", // Host (optional)
function() {
	console.log("Up and running");
});

Routers

foobar.com

Only works for foobar.com.

.yolo.nl

Routes hi.yolo.nl, sub.foo.yolo.nl but not yolo.nl.

/some-regexp/

A normal Regular Expression, e.g. some-regexp.com or baz.sume-regexp.hi.nz.

License

Attribution 3.0 Unported (CC BY 3.0)

Attribution

Just refer to this repository in some page like imprint, about or contact. Please.

Keywords

FAQs

Package last updated on 25 Jan 2013

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