Skip to content

Instantly share code, notes, and snippets.

@Usse
Created February 27, 2013 09:20
Show Gist options
  • Save Usse/5046574 to your computer and use it in GitHub Desktop.
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.
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