Created
July 28, 2016 05:58
-
-
Save solancer/f4a09db73ee2b80751056a3dd78c0cbc to your computer and use it in GitHub Desktop.
www-with-node-js-and-express
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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