Created
March 26, 2012 09:54
-
-
Save jzaefferer/2204237 to your computer and use it in GitHub Desktop.
Backbone app server - server static files or index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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