JSPM

multisite-handler

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q7947F
  • License ISC

Route http requests to different handler functions based on hostname of the incomming request

Package Exports

  • multisite-handler

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (multisite-handler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Multisite Request Handler

A simple library for routing an incomming message to different handlers based on the hostname in the request's Host header.

const http = require('http');
const multisite = require('multisite-hander');

const siteOne = (req, res) => res.end('Welcome to kittens.example, home of kitten things!')
const siteTwo = (req, res) => res.end('Welcome to anarchism.example, home of anarchist things!')

// Provide a dict object to map your domain names to site handlers
const handler = multisite({
    'kittens.example': siteOne,
    'anarchism.example': siteTwo
})

http.createServer(handler).listen(1234);

Also accepts an async function instead of a dict, so you can write more complex matchers (or even something async like looking names up in a database).

const handler = multisite(hostname => {
    // If the host header has a port specified, it will be stripped before this function is called
    if(hostname.match(/\bkittens\.example$/)) {
        return kittenSite;
    }
})