diff --git a/api/block-lists.js b/api/block-lists.js index c6c211f..c6ffacf 100644 --- a/api/block-lists.js +++ b/api/block-lists.js @@ -97,10 +97,7 @@ const checkDomainAgainstDnsServers = async (domain) => { const handler = middleware(async (url) => { const domain = new URL(url).hostname; const results = await checkDomainAgainstDnsServers(domain); - return { - statusCode: 200, - body: JSON.stringify({ blocklists: results }) - }; + return { blocklists: results }; }); module.exports = middleware(handler); diff --git a/api/hsts.js b/api/hsts.js index 02b2b4b..d06bf1c 100644 --- a/api/hsts.js +++ b/api/hsts.js @@ -8,11 +8,8 @@ const handler = async (url, event, context) => { body: JSON.stringify({ error: message }), }; }; - const hstsIncompatible = (message, statusCode = 200) => { - return { - statusCode: statusCode, - body: JSON.stringify({ message, compatible: false }), - }; + const hstsIncompatible = (message, compatible = false, hstsHeader = null ) => { + return { message, compatible, hstsHeader }; }; @@ -35,14 +32,7 @@ const handler = async (url, event, context) => { } else if (!preload) { resolve(hstsIncompatible(`HSTS header does not contain the preload directive.`)); } else { - resolve({ - statusCode: 200, - body: JSON.stringify({ - message: "Site is compatible with the HSTS preload list!", - compatible: true, - hstsHeader: hstsHeader, - }), - }); + resolve(hstsIncompatible(`Site is compatible with the HSTS preload list!`, true, hstsHeader)); } } }); diff --git a/api/ports.js b/api/ports.js index a435c6e..63e2c25 100644 --- a/api/ports.js +++ b/api/ports.js @@ -73,17 +73,11 @@ const handler = async (url, event, context) => { return errorResponse('The function timed out before completing.'); } - return { - statusCode: 200, - body: JSON.stringify({ openPorts, failedPorts }), - }; + return { openPorts, failedPorts }; }; const errorResponse = (message, statusCode = 444) => { - return { - statusCode: statusCode, - body: JSON.stringify({ error: message }), - }; + return { error: message }; }; module.exports = middleware(handler); diff --git a/api/rank.js b/api/rank.js index c34c2be..1947185 100644 --- a/api/rank.js +++ b/api/rank.js @@ -10,7 +10,7 @@ const handler = async (url) => { { auth: { username: process.env.TRANCO_USERNAME, password: process.env.TRANCO_API_KEY } } : {}; const response = await axios.get( - `https://tranco-list.eu/api/ranks/domain/${domain}`, { timeout: 2000 }, auth, + `https://tranco-list.eu/api/ranks/domain/${domain}`, { timeout: 5000 }, auth, ); if (!response.data || !response.data.ranks || response.data.ranks.length === 0) { return { skipped: `Skipping, as ${domain} isn't ranked in the top 100 million sites yet.`}; diff --git a/api/sitemap.js b/api/sitemap.js index ea8e4c7..9d77ec1 100644 --- a/api/sitemap.js +++ b/api/sitemap.js @@ -25,10 +25,7 @@ const handler = async (url) => { } if (!sitemapUrl) { - return { - statusCode: 404, - body: JSON.stringify({ skipped: 'No sitemap found' }), - }; + return { skipped: 'No sitemap found' }; } sitemapRes = await axios.get(sitemapUrl, { timeout: 5000 }); @@ -40,23 +37,14 @@ const handler = async (url) => { const parser = new xml2js.Parser(); const sitemap = await parser.parseStringPromise(sitemapRes.data); - return { - statusCode: 200, - body: JSON.stringify(sitemap), - }; + return sitemap; } catch (error) { // If error occurs console.log(error.message); if (error.code === 'ECONNABORTED') { - return { - statusCode: 500, - body: JSON.stringify({ error: 'Request timed out' }), - }; + return { error: 'Request timed out' }; } else { - return { - statusCode: 500, - body: JSON.stringify({ error: error.message }), - }; + return { error: error.message }; } } }; diff --git a/api/social-tags.js b/api/social-tags.js index a62bff9..f8b38a3 100644 --- a/api/social-tags.js +++ b/api/social-tags.js @@ -50,16 +50,9 @@ const handler = async (url) => { }; if (Object.keys(metadata).length === 0) { - return { - statusCode: 200, - body: JSON.stringify({ skipped: 'No metadata found' }), - }; + return { skipped: 'No metadata found' }; } - - return { - statusCode: 200, - body: JSON.stringify(metadata), - }; + return metadata; } catch (error) { return { statusCode: 500,