Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

subdomain

Node.js Express Subdomain Middleware.

express, subdomain, middleware, domain

readme

subdomain Git Tip

Node.js Express Subdomain Middleware.

I thought that this was a pretty sweet project express-subdomain-handler but I wanted it crafted a bit differently for my purposes and the ability to force HTTPS and removal of the unneccessary 'www' prefix. Thanks for the inspiration @WilsonPage

/etc/hosts

127.0.0.1 localhost
127.0.0.1 blog.localhost
127.0.0.1 writing.localhost

server

/**
 *
 * @example basic
 *
 * @description limited example
 * $ npm install express
 *
 */

var app
  , express = require('express')
  , subdomain = require('../lib/subdomain');

app = express();

app.use(subdomain({ base : 'localhost', removeWWW : true }));

app.get('/subdomain/blog/', function(request, response) {
  response.end('BLOG.LOCALHOST: "/"');
});

app.get('/', function(request, response) {
  response.end('LOCALHOST: "/"');
});

app.get('/hello', function(request, response) {
  response.end('LOCALHOST: "/hello"');
});

app.listen(8000, function() {
  console.log('> listening on port 8000');
});

available options

  • base - Required, the base domain name i.e. 'localhost'
  • removeWWW - Defaults to false
  • ignoreWWW - Defaults to false
  • prefix - Defaults to 'subdomain'
  • debug - Defaults to false

Bitdeli Badge

changelog

1.2.0 / 2014-08-06

  • Merge pull request #10 from knownasilya/patch-1
  • Add available options section to readme
  • Add prefix, defaults to 'subdomain'

1.1.0 / 2014-07-31

  • [dist] version bump to v1.1.0
  • [contrib] added @jeddawson
  • [minor] format
  • Merge pull request #9 from jeddawson/ignoreWWW
  • added ignore logic to first if instead of adding a nested condition
  • better to use regex early to weed out the www subdomains
  • added optional parameter ignoreWWW