Skip to content

Instantly share code, notes, and snippets.

@ashleygwilliams
Created February 14, 2013 21:03
Show Gist options
  • Save ashleygwilliams/4956381 to your computer and use it in GitHub Desktop.
Save ashleygwilliams/4956381 to your computer and use it in GitHub Desktop.
var express = require('express');
var taters = require('taters');
var enchilada = require('enchilada');
var makeup = require('makeup');
var veto = require('veto');
var browserkthx = require('browserkthx');
// we set certain settings based on production or not
var kProduction = process.env.NODE_ENV === 'production';
var app = express();
// serve the favicon from memory
app.use(express.favicon(__dirname + '/static/favicon.ico'));
// inform older browser users that their experience will be degraded
app.use(browserkthx({
ie: '< 9'
}));
// this does fingerprinting by rewriting html
app.use(taters({
cache: kProduction
}));
// this serves up anything .js after bundling
app.use(enchilada({
src: __dirname + '/static/'
compress: kProduction,
cache: kProduction
}));
// this serves up /static/css/widgets.css after using npm-css
// allows me to use css from widgets
app.use('/css/widgets.css', makeup(__dirname + '/static/css/widgets.css'));
// this handles every remaining static resources (images, etc)
app.use(express.static(__dirname + '/static'));
// monkey patch parameter error checking onto the req object
app.use(veto());
// explcitly inject the router
app.use(app.router);
// 404 handler
app.use(function(req, res, next) {
});
// error handler
app.use(function(err, req, res, next) {
});
/// other routes I put here or in separate files
/// see http://shtylman.com/post/expressjs-re-routing/
// reoutes just serve up json or in this case an html file
app.get('/', function(req, res, next) {
res.render('index');
});
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="/css/widgets.css">
</head>
<body>
<script src="/js/index.js"></script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment