Skip to content

Instantly share code, notes, and snippets.

@solancer
Created July 28, 2016 05:58
Show Gist options
  • Save solancer/f4a09db73ee2b80751056a3dd78c0cbc to your computer and use it in GitHub Desktop.
Save solancer/f4a09db73ee2b80751056a3dd78c0cbc to your computer and use it in GitHub Desktop.
www-with-node-js-and-express
var express = require("express");
var app = express.createServer();
var port = 9090;
app.all(/.*/, function(req, res, next) {
var host = req.header("host");
if (host.match(/^www\..*/i)) {
next();
} else {
res.redirect(301, "http://www." + host);
}
});
app.use(express.static(__dirname + "/public"));
app.listen(port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment