vhost fork made with typescript
npm install vhost-ts``sh`
yarn add vhost-ts
_or_
`sh`
npm install vhost-ts
`typescript`
import vhost from "vhost-ts";
Create a new middleware function to hand off request to handle when the incominghostname
host for the request matches . The function is called ashandle(req, res, next), like a standard middleware.
hostname can be a string or a RegExp object. When hostname is a string it can*
contain to match 1 or more characters in that section of the hostname. Whenhostname is a RegExp, it will be forced to case-insensitive (since hostnames are)
and will be forced to match based on the start and end of the hostname.
When host is matched and the request is sent down to a vhost handler, the req.vhosthostname
property will be populated with an object. This object will have numeric properties
corresponding to each wildcard (or capture group if RegExp object provided) and the that was matched.
`typescript
import vhost from "vhost-ts";
import express from "express";
const app = express();
app.use(
vhost("..example.com", function handle(req, res, next) {
// for match of "foo.bar.example.com:8080" against "..example.com":
console.dir(req.vhost.host); // => 'foo.bar.example.com:8080'
console.dir(req.vhost.hostname); // => 'foo.bar.example.com'
console.dir(req.vhost.length); // => 2
console.dir(req.vhost[0]); // => 'foo'
console.dir(req.vhost[1]); // => 'bar'
})
);
...
``