Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

GET /stats

  • Loading branch information...
commit 4215d10c37b1f44da5666f36898fa2533cf75ccc 1 parent dfafe67
@tj authored
Showing with 15 additions and 3 deletions.
  1. +15 −3 routes.js
View
18 routes.js
@@ -5,7 +5,8 @@ var rasterize = require('./lib/rasterize')
, join = path.join
, fs = require('fs');
-var dir = app.get('screenshots');
+var dir = app.get('screenshots')
+ , db = app.db;
/*
* GET home page.
@@ -20,19 +21,30 @@ app.get('/', function(req, res, next){
* GET screenshot.
*/
-app.get('/', function(req, res){
+app.get('/', function(req, res, next){
var url = req.query.url;
if (!url) return res.send(400);
var id = md5(url);
var path = join(dir, id + '.png');
rasterize(url, path, function(err){
- if (err) return res.send(500, 'Something broke!\n');
+ if (err) return next(err);
app.emit('screenshot', path, id);
res.sendfile(path);
});
});
/**
+ * GET stats.
+ */
+
+app.get('/stats', function(req, res){
+ db.hgetall('screenshot:stats', function(err, obj){
+ if (err) return next(err);
+ res.send(obj);
+ });
+});
+
+/**
* MD5 the given `str`.
*/
Please sign in to comment.
Something went wrong with that request. Please try again.