servie-vhost

Simple virtual host middleware for Servie

Usage no npm install needed!

<script type="module">
  import servieVhost from 'https://cdn.skypack.dev/servie-vhost';
</script>

README

Servie Vhost

NPM version NPM downloads Build status Test coverage

Simple virtual host middleware for Servie.

Installation

npm install servie-vhost --save

Usage

import { vhost, getHostFromUrl } from "servie-vhost";
import { compose } from "throwback";

const app = compose([
  vhost("admin.example.com", function(req) {
    return send(req, "Welcome to admin!");
  }),
  vhost(":subdomain.example.com", function(req) {
    return send(req, `Welcome to ${req.vhost[0]} subdomain!`);
  })
]);

For projects whose host is not in the header, they can switch between exported getHostFromHeader and getHostFromUrl functions, or define their own, as the third argument to vhost(hostname, fn, getHost).

TypeScript

This project is written using TypeScript and publishes the definitions directly to NPM.

License

Apache 2.0