Actually, I think something like this should probably work..
app.configure(function() { app.use(app.router);
app.use(express.static(__dirname + '/../public'));
app.use(function(req, res) {
res.status(404);
// Respond with html page:
if (req.accepts('html')) {
res.render('404', { url: req.url });
return;
}
if (req.accepts('json')) {
res.send({ error: 'Not found'});
// Default to plain text:
res.type('txt').send('Not found');
});
// Some node routes
app.get('/foo', function(req, res) {
res.send('foo');
});
// ...
// Define html5 routes used by angular app:
app.get('/user*', html5Route);
app.get('/user', html5Route);
app.get('/login', html5Route);
app.get('/logout', html5Route);
app.get('/posts*', html5Route);
app.get('/posts', html5Route);
//...
// Force all matching html5 routes through index.html:
function html5Route(req, res, next) {
res.sendfile(__dirname + '/public/index.html');
}