From 5bcf8ae51a9f990bcb72305fcdd98eab2671eba6 Mon Sep 17 00:00:00 2001 From: Simon Caron <8635747+simoncaron@users.noreply.github.com> Date: Sun, 10 Dec 2023 14:33:39 -0500 Subject: [PATCH] Implement DNS Caching with cacheable-lookup --- backend/classes/axios.js | 21 ++++++++++++--------- package-lock.json | 9 +++++++++ package.json | 1 + 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/backend/classes/axios.js b/backend/classes/axios.js index 2569629..db3ad5b 100644 --- a/backend/classes/axios.js +++ b/backend/classes/axios.js @@ -1,17 +1,20 @@ const axios = require("axios"); const https = require('https'); +const CacheableLookup = require('cacheable-lookup'); + +const cacheable = new CacheableLookup(); const agent = new https.Agent({ - rejectUnauthorized: (process.env.REJECT_SELF_SIGNED_CERTIFICATES || 'true').toLowerCase() ==='true' - }); + rejectUnauthorized: (process.env.REJECT_SELF_SIGNED_CERTIFICATES || 'true').toLowerCase() === 'true' +}); +cacheable.install(agent); const axios_instance = axios.create({ - httpsAgent: agent - }); + httpsAgent: agent +}); - module.exports = - { - axios:axios_instance - }; - \ No newline at end of file +module.exports = +{ + axios: axios_instance +}; diff --git a/package-lock.json b/package-lock.json index d8c7747..b474cbe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "axios": "^1.5.1", "axios-cache-interceptor": "^1.3.1", "bootstrap": "^5.2.3", + "cacheable-lookup": "^7.0.0", "compare-versions": "^6.0.0-rc.1", "compression": "^1.7.4", "config": "^3.3.9", @@ -7346,6 +7347,14 @@ "resolved": "https://registry.npmjs.org/cache-parser/-/cache-parser-1.2.4.tgz", "integrity": "sha512-O0KwuHuJnbHUrghHi2kGp0SxnWSIBXTYt7M8WVhW0kbPRUNUKoE/Of6e1rRD6AAxmfxFunKnt90yEK09D+sc5g==" }, + "node_modules/cacheable-lookup": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-7.0.0.tgz", + "integrity": "sha512-+qJyx4xiKra8mZrcwhjMRMUhD5NR1R8esPkzIYxX96JiecFoxAXFuz/GpR3+ev4PE1WamHip78wV0vcmPQtp8w==", + "engines": { + "node": ">=14.16" + } + }, "node_modules/call-bind": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz", diff --git a/package.json b/package.json index 1045fca..f5eb694 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "axios": "^1.5.1", "axios-cache-interceptor": "^1.3.1", "bootstrap": "^5.2.3", + "cacheable-lookup": "^7.0.0", "compare-versions": "^6.0.0-rc.1", "compression": "^1.7.4", "config": "^3.3.9",