Skip to content

Instantly share code, notes, and snippets.

@jzaefferer
Created March 26, 2012 09:54
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 jzaefferer/2204237 to your computer and use it in GitHub Desktop.
Save jzaefferer/2204237 to your computer and use it in GitHub Desktop.
Backbone app server - server static files or index.html
var connect = require('connect');
var httpPort = 8090;
var httpHost = "localhost";
var staticDir = __dirname;
var staticFiles = /\.(?:js|jpg|png|gif|json|css|ico|html|manifest|mp3|txt)(?:\?.+)?$/;
function route(app) {
app.get(/.*/, function(request, response, next) {
if (!(staticFiles).test(request.url)) {
request.url = '/index.html';
}
next();
});
}
connect.createServer(
connect.router(route),
connect.static(staticDir)
).listen(httpPort, httpHost, function() {
console.log('HTTP Server running at http://%s:%d', httpHost, httpPort);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment