Skip to content

Instantly share code, notes, and snippets.

@aroc
Last active December 12, 2015 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aroc/4684626 to your computer and use it in GitHub Desktop.
Save aroc/4684626 to your computer and use it in GitHub Desktop.
Helpful for using Node as a local server for Backbone. Very crude, could likely be far more elegant.
var express = require('express');
var app = express();
app.get('*', function(req, res) {
var staticTopLevelFolders = [
'assets',
'app'
]
var requestedTopLevelFolder = (req._parsedUrl.pathname).split('/')[1];
if (staticTopLevelFolders.indexOf(requestedTopLevelFolder) !== -1) {
res.sendfile('.' + req._parsedUrl.pathname);
} else {
res.sendfile('index.html');
}
});
app.listen(8080);
console.log('listening on port 8080');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment