Skip to content

Commit

Permalink
Used got lib instead of request to fix prototype pollution
Browse files Browse the repository at this point in the history
  • Loading branch information
Sankarsan Kampa committed Feb 16, 2018
1 parent 5153e23 commit e3757ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
22 changes: 7 additions & 15 deletions lib/Trivia.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @license MIT
*/

const request = require('request');
const request = require('got');

const BASE_URL = {
API: 'https://opentdb.com/api.php',
Expand Down Expand Up @@ -45,13 +45,9 @@ class Trivia {
*/
getCategories() {
return new Promise((resolve, reject) => {
request(this.CATEGORIES_URL, (error, response, body) => {
if (error) reject(error);
if (response) {
if (response.statusCode === 200) resolve(JSON.parse(body));
else reject(`${response.statusCode}: ${response.statusMessage}`);
}
});
request(this.CATEGORIES_URL, { json: true }).then(response => {
resolve(response.body);
}).catch(e => reject(e));
});
}

Expand Down Expand Up @@ -112,13 +108,9 @@ class Trivia {
}

return new Promise((resolve, reject) => {
request(url, (error, response, body) => {
if (error) reject(error);
if (response) {
if (response.statusCode === 200) resolve(JSON.parse(body));
else reject(`${response.statusCode}: ${response.statusMessage}`);
}
});
request(url, { json: true }).then(response => {
resolve(response.body);
}).catch(e => reject(e));
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trivia-api",
"version": "1.0.0",
"version": "1.0.1",
"description": "A nodejs module for getting trivia questions in all your fancy projects, in a pretty simple way.",
"keywords": [
"trivia",
Expand Down Expand Up @@ -28,7 +28,7 @@
"url": "https://github.com/snkrsnkampa/node-trivia-api/issues"
},
"dependencies": {
"request": "^2.83.0"
"got": "^8.1.0"
},
"devDependencies": {
"eslint": "^4.7.2"
Expand Down

0 comments on commit e3757ca

Please sign in to comment.