Inspired by Rack::ForceDomain it directs all traffic to a single domain with a 301 redirect.
This is useful where you are hosting your node site with a PaaS provide like Joyent or Nodester and want to ensure all visitors are on the same domain.
via npm
npm install connect-force-domain
For connect
var connect = require('connect'),
http = require('http'),
forceDomain = require('connect-force-domain');
var app = connect()
.use(forceDomain('shapeshed.com'))
http.Server(app).listen(3000);
For express
var express = require('express'),
forceDomain = require('connect-force-domain');
var app = module.exports = express.createServer();
app.configure(function(){
app.use(forceDomain('shapeshed.com');
});
app.listen(3000);