Created
February 27, 2013 09:20
-
-
Save Usse/5046574 to your computer and use it in GitHub Desktop.
Node.js server file that redirect all the paths without extension to the index.
Usefull for AngularJS development.
This file contains hidden or 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 serverPort = 3000; | |
var express = require("express"), | |
app = express(), | |
port = serverPort; | |
app.use(express.methodOverride()); | |
app.use(express.bodyParser()); | |
app.use(express.static(__dirname)); | |
app.use(express.errorHandler({ | |
dumpExceptions: true, | |
showStack: true | |
})); | |
app.use(app.router); | |
/* Send anything with a file extension as normal */ | |
app.get("*.*", function(req, res) { | |
res.sendfile('.' + req.url); | |
}); | |
/* Intercept any paths and send index.html */ | |
app.get("*", function(req, res) { | |
res.sendfile("./index.html"); | |
}); | |
app.listen(port); | |
console.log("Listening on port " + serverPort); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment