From 8b87d0c2a0cca73a640722121ca49a001d29d3e1 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 10 Aug 2017 12:54:23 +1000 Subject: [PATCH 1/5] allow api server to pass though hitsPerPage and page to algolia search --- apiServer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apiServer.js b/apiServer.js index 690d4c7249..cf8c68a276 100755 --- a/apiServer.js +++ b/apiServer.js @@ -83,11 +83,15 @@ app.get('/libraries', function(req, res) { res.setHeader("Expires", new Date(Date.now() + 360 * 60 * 1000).toUTCString()); var fields = (req.query.fields && req.query.fields.split(',')) || []; + if (req.query.search) { + var searchParams = { typoTolerance: 'min', // only keep the minimum typos - hitsPerPage: 1000 // maximum + page: req.query.page || 0, // default + hitsPerPage: req.query.hitsPerPage || 1000 // maximum }; + algoliaIndex.search(req.query.search, searchParams, function(error, content) { if (error) { res.status(500).send(error.message); @@ -120,6 +124,7 @@ app.get('/libraries', function(req, res) { } } }); + app.get('/libraries/:library', function(req, res) { var results; var fields = (req.query.fields && req.query.fields.split(',')) || false; From 0683c797417db05e70e12adb7264306976ffb43c Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 10 Aug 2017 13:07:18 +1000 Subject: [PATCH 2/5] add 'hitsPerPage' and 'page' to api documentation --- templates/api.html | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/templates/api.html b/templates/api.html index b1507d52dc..c09a767882 100644 --- a/templates/api.html +++ b/templates/api.html @@ -19,7 +19,7 @@

- You can query cdnjs via our API as below + You can query cdnjs via our API as belows

Without any query parameters it will return the name and main file URL of every library on cdnjs:

https://api.cdnjs.com/libraries @@ -40,6 +40,14 @@

CDNJS (except auto-update config, we'll only return the auto-update type (currently npm or git)

+ The API will return the maximum results by default (1000), but you can limit these the "hitsPerPage" query +

+ https://api.cdnjs.com/libraries?search=[query]&hitsPerPage=10 +

+ If you are using the "hitsPerPage" query, you can also use "page" to paginate (defaulting at 0) +

+ https://api.cdnjs.com/libraries?search=[query]&hitsPerPage=10&page=2 +

API will return minified result by default, if you wanna have a human readable result, try output=human like so: From eb966b67d92430e7cc62ff52db20e84b68030051 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 10 Aug 2017 13:08:14 +1000 Subject: [PATCH 3/5] fix typo --- templates/api.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/api.html b/templates/api.html index c09a767882..13fe5a4e4e 100644 --- a/templates/api.html +++ b/templates/api.html @@ -19,7 +19,7 @@

- You can query cdnjs via our API as belows + You can query cdnjs via our API as below

Without any query parameters it will return the name and main file URL of every library on cdnjs:

https://api.cdnjs.com/libraries From 854839a4e1eb30653248bdb67f299bd4a787d5e2 Mon Sep 17 00:00:00 2001 From: Tim Holman Date: Thu, 10 Aug 2017 16:40:10 +1000 Subject: [PATCH 4/5] copy fix --- templates/api.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/api.html b/templates/api.html index 13fe5a4e4e..99b900420b 100644 --- a/templates/api.html +++ b/templates/api.html @@ -40,7 +40,7 @@

CDNJS (except auto-update config, we'll only return the auto-update type (currently npm or git)

- The API will return the maximum results by default (1000), but you can limit these the "hitsPerPage" query + The API will return the maximum results by default (1000), but you can limit these with the "hitsPerPage" query

https://api.cdnjs.com/libraries?search=[query]&hitsPerPage=10

From 1465fdd0c5127572fd29bffa1409567d5ca38009 Mon Sep 17 00:00:00 2001 From: Tim Holman Date: Fri, 8 Sep 2017 09:41:12 -0700 Subject: [PATCH 5/5] Remove whitespace --- apiServer.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apiServer.js b/apiServer.js index cf8c68a276..ef4502645d 100755 --- a/apiServer.js +++ b/apiServer.js @@ -83,15 +83,12 @@ app.get('/libraries', function(req, res) { res.setHeader("Expires", new Date(Date.now() + 360 * 60 * 1000).toUTCString()); var fields = (req.query.fields && req.query.fields.split(',')) || []; - if (req.query.search) { - var searchParams = { typoTolerance: 'min', // only keep the minimum typos page: req.query.page || 0, // default hitsPerPage: req.query.hitsPerPage || 1000 // maximum }; - algoliaIndex.search(req.query.search, searchParams, function(error, content) { if (error) { res.status(500).send(error.message); @@ -124,7 +121,6 @@ app.get('/libraries', function(req, res) { } } }); - app.get('/libraries/:library', function(req, res) { var results; var fields = (req.query.fields && req.query.fields.split(',')) || false;