subdomain

Node.JS Express Subdomain Middleware.

npm install subdomain
2 downloads in the last day
24 downloads in the last week
56 downloads in the last month

subdomain

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


var subdomain = require('subdomain');

var express = require('express')
  , app = express.createServer();

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

app.get('/subdomain/blog/', function(request, response) {
  response.end('<p>blog.mydomain.com</p>');
});

app.get('/subdomain/api/users/', function(request, response) {
  response.end('<p>api.mydomain.com/users</p>');
});

app.get('/hello', function(request, response) {
  response.end('<p>mydomain.com/hello</p>');
});

app.listen(8000);
npm loves you