npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

thunderflurry-virtualhost

v0.1.3

Published

Middleware for express or connect to create virtual, self-contained application nodes in ThunderFlurry.

Downloads

6

Readme

Thunderflurry Virtual Host

Middleware for express or connect to create virtual, self-contained application nodes in ThunderFlurry. Based originally on virtual-host, overhauled to add features specifically needed for ThunderFlurry's core.

Install

$ npm install thunderflurry-virtualhost --save

Requre

var host = require('thunderflurry-virtualhost')(express);

Or ES7

import virtualhost from 'thunderflurry-virtualhost';
const host = virtualhost(express);

API

vhost(hostname)

Creates an instance of express (or connect), and a middleware you can .use in your main application.

You must provide a hostname to restrict the hostnames the virtual server will be used on. hostname is used to build a regular expression to test against req.headers.host, after stripping out the port. Stars '*' will be converted to (.*). You can use any characters in this set: [a-zA-Z_0-9.*-]. You may also provide an array of hostnames to hostname.

You can also just use a RegExp object as a hostname directly.

Example hostnames:

vhost('*')                // results in /^(.*)$/
vhost('*.foo.com')        // results in /^(.*)\.foo\.com$/i
vhost('www.*.com')        // results in /^www\.(.*)\.com$/i
vhost(/^www\.foo\.com$/i) // results in /^www\.foo\.com$/i
vhost(['www.*', 'test.*'] // results in /^www\.(.*)$/i AND /^test\.(.*)$/i

Special case: The tile ~ is a special case that will match localhost and the root domain. Example:

vhost('~')                // matches localhost and example.com
vhost(['www.*', '~'])     // matches localhost and example.com and www.example.com

vhost(hostname).off

Turns off the middleware, it will automatically .next all future requests.

var express = require('express');
var vhost = require('virtual-host')(express);
var www = vhost('www.*');

// configure www

app.use(www);

somethingBadHappens(function(){
    www.off(); // disable www
});

vhost(hostname).on

Turns on the middleware, it will start handling requests once again.

var express = require('express');
var vhost = require('virtual-host')(express);
var www = vhost('www.*');

// configure www

app.use(www);

somethingGoodHappens(function(){
    www.on(); // re-enable www
});

vhost(hostname).server

Exposes the express or connect instance used by this vhost.

Usage

var express = require('express');
var vhost = require('virtual-host')(express);
var app = express();
var www = vhost('www.*');

www.use(function(req,res,next){
    console.log(req.url);

    if(req.url === '/off'){
        www.off();
        res.send(500);
    }else{
        res.send(200);
    }    
});

app.use(www);

vhost(hostname).handlesRoot

Returns true if ~ was used as a hostname and false if it wasn't included.

Usage

var express = require('express');
var vhost = require('virtual-host')(express);
var app = express();
var www = vhost('~');

if (www.handlesRoot) {
   console.log('Tilde was used');
}

vhost(hostname).hosts

Returns the array of hosts the adapter is handling.

Usage

var express = require('express');
var vhost = require('virtual-host')(express);
var app = express();
var www = vhost(['~', 'www.*']);

www.forEach(function (item) {
  console.log(item);
}