Express and URL rewriting | HTML5 history

I'm trying to build a simple server to serve a single HTML page where all the logics are handled by Angular. As far as I'm using the HTML5 history mode I'm able to navigate through standard URLs.

Now, to make this work I need to enable URL rewriting. I tried with this bunch of lines and although return always the correct HTML page, the URL vary and does not keep the initial value. For example /popular should load index.html and leave the URL /popular so that the JS logic can load the desired page.

Here follows the express code.

var express = require("express");
var app = express();

app.configure(function(){
  app.use(express.static(__dirname + '/dist'));
}); 

app.get("/*", function(req, res, next){
  res.sendfile(__dirname + '/dist/index.html');
});

app.listen(3000);

Any suggestion is appreciated. Thanks everyone.

You need to set the root directory for relative filenames.

app.all('/*', function(req, res) {
  res.sendfile('index.html', { root: __dirname+'/dist' });
});