From 60c0e4beb2d94b43fbf5b0e4a049e9bf8e54c077 Mon Sep 17 00:00:00 2001 From: Paulo Vitor Magacho da Silva Date: Sat, 28 Jan 2017 09:25:28 -0200 Subject: [PATCH 1/2] Fix token issue --- web.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/web.js b/web.js index ef9fe60..9bfcf65 100644 --- a/web.js +++ b/web.js @@ -205,6 +205,11 @@ app.get('/api/search', tokenOK, function(req, res) { if (req.query.uri) { query.where('uri').equals(req.query.uri); } + default: + query = AnnotationModel.find(); + if (req.query.uri) { + query.where('uri').equals(req.query.uri); + } break; } @@ -251,15 +256,10 @@ app.get('/api/search', tokenOK, function(req, res) { else { query.exec(function(err, annotations) { if (!err) { - // console.info(annotations); - if (annotations.length > 0) { + console.info(annotations); return res.send({ 'rows': annotations }); - } - else { - return res.send(204, 'Successfully deleted annotation.'); - } } else { return console.log(err); @@ -407,8 +407,8 @@ function tokenOK(req, res, next) { }; function inWindow(decoded, next) { - var issuedAt = decoded.issuedAt; - var ttl = decoded.ttl; + var issuedAt = decoded.iat; + var ttl = decoded.exp; var issuedSeconds = new Date(issuedAt) / 1000; var nowSeconds = new Date().getTime() / 1000; var diff = ((nowSeconds - issuedSeconds)); From 548a0e8ecec4b49f0423677c8428fdfd8fc06cab Mon Sep 17 00:00:00 2001 From: Paulo Vitor Magacho da Silva Date: Tue, 31 Jan 2017 09:11:23 -0200 Subject: [PATCH 2/2] Added index --- web.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web.js b/web.js index 9bfcf65..8c2e1de 100644 --- a/web.js +++ b/web.js @@ -145,6 +145,8 @@ var Annotation = new Schema({ } }); +Annotation.index({uri: 1}); + var AnnotationModel = mongoose.model('Annotation', Annotation); // DB