Add cache-control headers.

This commit is contained in:
lucaswadedavis 2016-12-19 15:43:48 -08:00
parent b78dbe2b03
commit e9fd0b8214

View file

@ -41,11 +41,14 @@ var app = express();
app.use(express.static(__dirname + '/images'));
var cacheTimeout = 60 * 60 * 24 * 30;
app.get('/', function(req, res) {
var width = 400;
var seed = uuid();
var canvas = composeImage(width, width, seed);
var buffer = canvas.toBuffer();
res.set('Cache-Control', 'max-age=' + cacheTimeout);
res.set('Content-length', buffer.length);
res.type('png');
res.end(buffer, 'binary');
@ -56,6 +59,7 @@ app.get('/:width', function(req, res) {
var seed = uuid();
var canvas = composeImage(width, width, seed);
var buffer = canvas.toBuffer();
res.set('Cache-Control', 'max-age=' + cacheTimeout);
res.set('Content-length', buffer.length);
res.type('png');
res.end(buffer, 'binary');
@ -66,6 +70,7 @@ app.get('/:width/:seed', function(req, res) {
var seed = sanitize(req.params.seed) || uuid();
var canvas = composeImage(width, width, seed);
var buffer = canvas.toBuffer();
res.set('Cache-Control', 'max-age=' + cacheTimeout);
res.set('Content-length', buffer.length);
res.type('png');
res.end(buffer, 'binary');