Skip to content

Instantly share code, notes, and snippets.

@facultymatt
Created November 8, 2013 21:51
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 facultymatt/7378275 to your computer and use it in GitHub Desktop.
Save facultymatt/7378275 to your computer and use it in GitHub Desktop.
Simple server
/**
* Add express to package.json
* Keep the app.get('*') for nice sinlge page app support
*
*/
var express = require("express"),
app = express(),
port = parseInt(process.env.PORT, 10) || 4567;
app.configure(function() {
app.use(express.methodOverride());
app.use(express.bodyParser());
app.use(express.static(__dirname + '/app'));
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
app.use(app.router);
});
// send all non-api requests to our main index.html page, which starts our app
// this is a nice way to support non hash links on single page apps... and why we started using
// angular and genesis in the first place <3
app.get('*', function(req, res, next) {
res.redirect('/#' + req.url);
});
app.listen(port, function() {
console.log("Express server listening on port " + port);
});
@facultymatt
Copy link
Author

Note if this is not root level, use app.use(express.static(path.join(__dirname, '../app'))); or similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment