Last active
December 12, 2015 00:38
-
-
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.
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 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