Permalink
Browse files

serve pre-rasterized urls

normally varnish would just do this, but
for the sake of development this will
speed things up
  • Loading branch information...
tj committed Dec 18, 2011
1 parent a112a32 commit 892840603ed6fb2557e97c5c70444f98e748f544
Showing with 18 additions and 0 deletions.
  1. +1 −0 events.js
  2. +17 −0 routes.js
View
@@ -9,6 +9,7 @@ var db = app.db;
app.on('screenshot', function(url, path, id){
var now = Date.now();
console.log('screenshot - saving meta-data');
+ db.hset('screenshot:url:id', url, id);
db.zadd('screenshot:ids', now, id);
db.zadd('screenshot:urls', now, url);
db.zadd('screenshot:hosts', now, parse(url).host);
View
@@ -56,6 +56,23 @@ app.get('/screenshots/:from..:to', function(req, res, next){
});
});
+/**
+ * GET serve when already rasterized.
+ */
+
+app.get('/:url(*)', function(req, res, next){
+ var url = utils.url(req.params.url);
+ db.hget('screenshot:url:id', url, function(err, id){
+ if (err) return next(err);
+ if (!id) return next();
+ db.hget('screenshot:' + id, 'path', function(err, path){
+ if (err) return next(err);
+ console.log('screenshot - serving rasterized %s', url);
+ res.sendfile(path);
+ });
+ });
+});
+
/*
* GET screenshot.
*/

0 comments on commit 8928406

Please sign in to comment.