diff --git a/api/archives.js b/api/archives.js index c5d9c04..6c7cb48 100644 --- a/api/archives.js +++ b/api/archives.js @@ -80,4 +80,5 @@ const getWaybackData = async (url) => { } }; -exports.handler = middleware(getWaybackData); +module.exports = middleware(getWaybackData); +module.exports.handler = middleware(getWaybackData); diff --git a/api/block-lists.js b/api/block-lists.js index 75524ea..c6c211f 100644 --- a/api/block-lists.js +++ b/api/block-lists.js @@ -94,7 +94,7 @@ const checkDomainAgainstDnsServers = async (domain) => { return results; }; -exports.handler = middleware(async (url) => { +const handler = middleware(async (url) => { const domain = new URL(url).hostname; const results = await checkDomainAgainstDnsServers(domain); return { @@ -103,3 +103,6 @@ exports.handler = middleware(async (url) => { }; }); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); + diff --git a/api/carbon.js b/api/carbon.js index 40cecdf..a2c5210 100644 --- a/api/carbon.js +++ b/api/carbon.js @@ -48,4 +48,5 @@ const handler = async (url) => { } }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/cookies.js b/api/cookies.js index 3832195..1f10470 100644 --- a/api/cookies.js +++ b/api/cookies.js @@ -54,4 +54,5 @@ const handler = async (url) => { return { headerCookies, clientCookies }; }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/dns-server.js b/api/dns-server.js index 5be9385..c9af720 100644 --- a/api/dns-server.js +++ b/api/dns-server.js @@ -1,7 +1,7 @@ const dns = require('dns'); const dnsPromises = dns.promises; const axios = require('axios'); -const commonMiddleware = require('./_common/middleware'); +const middleware = require('./_common/middleware'); const handler = async (url) => { try { @@ -41,4 +41,5 @@ const handler = async (url) => { } }; -exports.handler = commonMiddleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/dns.js b/api/dns.js index f7774a9..34d6c02 100644 --- a/api/dns.js +++ b/api/dns.js @@ -51,4 +51,5 @@ const handler = async (url) => { } }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/dnssec.js b/api/dnssec.js index 5f04044..1ce4bfb 100644 --- a/api/dnssec.js +++ b/api/dnssec.js @@ -1,7 +1,7 @@ const https = require('https'); -const commonMiddleware = require('./_common/middleware'); // Make sure this path is correct +const middleware = require('./_common/middleware'); // Make sure this path is correct -const fetchDNSRecords = async (domain, event, context) => { +const handler = async (domain) => { const dnsTypes = ['DNSKEY', 'DS', 'RRSIG']; const records = {}; @@ -49,4 +49,6 @@ const fetchDNSRecords = async (domain, event, context) => { return records; }; -exports.handler = commonMiddleware(fetchDNSRecords); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); + diff --git a/api/features.js b/api/features.js index ced8757..67e4c81 100644 --- a/api/features.js +++ b/api/features.js @@ -1,7 +1,7 @@ const https = require('https'); const middleware = require('./_common/middleware'); -const builtWithHandler = async (url) => { +const handler = async (url) => { const apiKey = process.env.BUILT_WITH_API_KEY; if (!url) { @@ -45,4 +45,5 @@ const builtWithHandler = async (url) => { } }; -exports.handler = middleware(builtWithHandler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/firewall.js b/api/firewall.js index f90e108..39afde3 100644 --- a/api/firewall.js +++ b/api/firewall.js @@ -102,4 +102,5 @@ const handler = async (url) => { } }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/get-ip.js b/api/get-ip.js index 8df95bc..303a0f1 100644 --- a/api/get-ip.js +++ b/api/get-ip.js @@ -18,4 +18,6 @@ const handler = async (url) => { return await lookupAsync(address); }; -exports.handler = middleware(handler); + +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/headers.js b/api/headers.js index 79b4c4a..84b179f 100644 --- a/api/headers.js +++ b/api/headers.js @@ -15,4 +15,5 @@ const handler = async (url, event, context) => { } }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/hsts.js b/api/hsts.js index 9dfed13..02b2b4b 100644 --- a/api/hsts.js +++ b/api/hsts.js @@ -1,7 +1,7 @@ const https = require('https'); const middleware = require('./_common/middleware'); -exports.handler = middleware(async (url, event, context) => { +const handler = async (url, event, context) => { const errorResponse = (message, statusCode = 500) => { return { statusCode: statusCode, @@ -53,5 +53,8 @@ exports.handler = middleware(async (url, event, context) => { req.end(); }); -}); +}; + +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/http-security.js b/api/http-security.js index 0cd644d..77daf5a 100644 --- a/api/http-security.js +++ b/api/http-security.js @@ -22,4 +22,5 @@ const handler = async (url) => { } }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/legacy-rank.js b/api/legacy-rank.js index 9a9f795..19dd1bd 100644 --- a/api/legacy-rank.js +++ b/api/legacy-rank.js @@ -66,5 +66,6 @@ return new Promise((resolve, reject) => { }); }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/linked-pages.js b/api/linked-pages.js index 7e1ee8a..60dd88f 100644 --- a/api/linked-pages.js +++ b/api/linked-pages.js @@ -1,7 +1,7 @@ const axios = require('axios'); const cheerio = require('cheerio'); const urlLib = require('url'); -const commonMiddleware = require('./_common/middleware'); +const middleware = require('./_common/middleware'); const handler = async (url) => { const response = await axios.get(url); @@ -45,4 +45,5 @@ const handler = async (url) => { return { internal: internalLinks, external: externalLinks }; }; -exports.handler = commonMiddleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/mail-config.js b/api/mail-config.js index 16fb7e2..0f24cab 100644 --- a/api/mail-config.js +++ b/api/mail-config.js @@ -1,4 +1,4 @@ -const commonMiddleware = require('./_common/middleware'); +const middleware = require('./_common/middleware'); const dns = require('dns').promises; const URL = require('url-parse'); @@ -72,4 +72,5 @@ const handler = async (url, event, context) => { } }; -module.exports.handler = commonMiddleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/ports.js b/api/ports.js index 7a15d9f..a435c6e 100644 --- a/api/ports.js +++ b/api/ports.js @@ -86,4 +86,5 @@ const errorResponse = (message, statusCode = 444) => { }; }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/quality.js b/api/quality.js index 2c606db..7f2e3f1 100644 --- a/api/quality.js +++ b/api/quality.js @@ -4,10 +4,6 @@ const middleware = require('./_common/middleware'); const handler = async (url, event, context) => { const apiKey = process.env.GOOGLE_CLOUD_API_KEY; - if (!url) { - throw new Error('URL param is required'); - } - if (!apiKey) { throw new Error('API key (GOOGLE_CLOUD_API_KEY) not set'); } @@ -19,4 +15,5 @@ const handler = async (url, event, context) => { return response.data; }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/rank.js b/api/rank.js index a156d38..c34c2be 100644 --- a/api/rank.js +++ b/api/rank.js @@ -21,4 +21,6 @@ const handler = async (url) => { } }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); + diff --git a/api/redirects.js b/api/redirects.js index 9f53b02..cd815b1 100644 --- a/api/redirects.js +++ b/api/redirects.js @@ -24,4 +24,6 @@ const handler = async (url) => { }; const middleware = require('./_common/middleware'); -exports.handler = middleware(handler); + +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/robots-txt.js b/api/robots-txt.js index c21088f..9f008e3 100644 --- a/api/robots-txt.js +++ b/api/robots-txt.js @@ -67,4 +67,5 @@ const handler = async function(url) { } }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/screenshot.js b/api/screenshot.js index 49906f0..c68f27e 100644 --- a/api/screenshot.js +++ b/api/screenshot.js @@ -2,7 +2,7 @@ const puppeteer = require('puppeteer-core'); const chromium = require('chrome-aws-lambda'); const middleware = require('./_common/middleware'); -const screenshotHandler = async (targetUrl) => { +const handler = async (targetUrl) => { if (!targetUrl) { throw new Error('URL is missing from queryStringParameters'); @@ -58,4 +58,5 @@ const screenshotHandler = async (targetUrl) => { } }; -exports.handler = middleware(screenshotHandler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/security-txt.js b/api/security-txt.js index c2cd59c..dd08ca0 100644 --- a/api/security-txt.js +++ b/api/security-txt.js @@ -38,7 +38,7 @@ const isPgpSigned = (result) => { return false; }; -const securityTxtHandler = async (urlParam) => { +const handler = async (urlParam) => { let url; try { @@ -69,8 +69,6 @@ const securityTxtHandler = async (urlParam) => { return { isPresent: false }; }; -exports.handler = middleware(securityTxtHandler); - async function fetchSecurityTxt(baseURL, path) { return new Promise((resolve, reject) => { const url = new URL(path, baseURL); @@ -91,3 +89,6 @@ async function fetchSecurityTxt(baseURL, path) { }); }); } + +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/sitemap.js b/api/sitemap.js index 816d4f1..ea8e4c7 100644 --- a/api/sitemap.js +++ b/api/sitemap.js @@ -1,4 +1,4 @@ -const commonMiddleware = require('./_common/middleware'); +const middleware = require('./_common/middleware'); const axios = require('axios'); const xml2js = require('xml2js'); @@ -61,4 +61,6 @@ const handler = async (url) => { } }; -exports.handler = commonMiddleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); + diff --git a/api/social-tags.js b/api/social-tags.js index 8d15232..a62bff9 100644 --- a/api/social-tags.js +++ b/api/social-tags.js @@ -1,4 +1,4 @@ -const commonMiddleware = require('./_common/middleware'); +const middleware = require('./_common/middleware'); const axios = require('axios'); const cheerio = require('cheerio'); @@ -68,4 +68,5 @@ const handler = async (url) => { } }; -exports.handler = commonMiddleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/ssl.js b/api/ssl.js index fb2217d..1eb5c55 100644 --- a/api/ssl.js +++ b/api/ssl.js @@ -1,7 +1,7 @@ const tls = require('tls'); const middleware = require('./_common/middleware'); -const fetchSiteCertificateHandler = async (urlString) => { +const handler = async (urlString) => { try { const parsedUrl = new URL(urlString); const options = { @@ -40,4 +40,5 @@ const fetchSiteCertificateHandler = async (urlString) => { } }; -exports.handler = middleware(fetchSiteCertificateHandler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/status.js b/api/status.js index ce4f478..2a70b66 100644 --- a/api/status.js +++ b/api/status.js @@ -2,7 +2,7 @@ const https = require('https'); const { performance, PerformanceObserver } = require('perf_hooks'); const middleware = require('./_common/middleware'); -const checkURLHandler = async (url) => { +const handler = async (url) => { if (!url) { throw new Error('You must provide a URL query parameter!'); } @@ -55,4 +55,5 @@ const checkURLHandler = async (url) => { } }; -exports.handler = middleware(checkURLHandler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/tech-stack.js b/api/tech-stack.js index 5820f6d..d649d2b 100644 --- a/api/tech-stack.js +++ b/api/tech-stack.js @@ -1,7 +1,7 @@ const Wappalyzer = require('wappalyzer'); const middleware = require('./_common/middleware'); -const analyzeSiteTechnologies = async (url) => { +const handler = async (url) => { const options = {}; const wappalyzer = new Wappalyzer(options); @@ -27,4 +27,5 @@ const analyzeSiteTechnologies = async (url) => { } }; -exports.handler = middleware(analyzeSiteTechnologies); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/threats.js b/api/threats.js index 7d87ce1..afff98c 100644 --- a/api/threats.js +++ b/api/threats.js @@ -5,6 +5,9 @@ const middleware = require('./_common/middleware'); const getGoogleSafeBrowsingResult = async (url) => { try { const apiKey = process.env.GOOGLE_CLOUD_API_KEY; + if (!apiKey) { + return { error: 'GOOGLE_CLOUD_API_KEY is required for the Google Safe Browsing check' }; + } const apiEndpoint = `https://safebrowsing.googleapis.com/v4/threatMatches:find?key=${apiKey}`; const requestBody = { @@ -63,11 +66,15 @@ const getPhishTankResult = async (url) => { } const getCloudmersiveResult = async (url) => { + const apiKey = process.env.CLOUDMERSIVE_API_KEY; + if (!apiKey) { + return { error: 'CLOUDMERSIVE_API_KEY is required for the Cloudmersive check' }; + } try { const endpoint = 'https://api.cloudmersive.com/virus/scan/website'; const headers = { 'Content-Type': 'application/x-www-form-urlencoded', - 'Apikey': process.env.CLOUDMERSIVE_API_KEY, + 'Apikey': apiKey, }; const data = `Url=${encodeURIComponent(url)}`; const response = await axios.post(endpoint, data, { headers }); @@ -92,4 +99,5 @@ const handler = async (url) => { } }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/tls.js b/api/tls.js index 20e4065..09aeaeb 100644 --- a/api/tls.js +++ b/api/tls.js @@ -25,4 +25,5 @@ const handler = async (url) => { } }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/trace-route.js b/api/trace-route.js index 8d7b10b..2b71e48 100644 --- a/api/trace-route.js +++ b/api/trace-route.js @@ -2,7 +2,7 @@ const traceroute = require('traceroute'); const url = require('url'); const middleware = require('./_common/middleware'); -const executeTraceroute = async (urlString, context) => { +const handler = async (urlString, context) => { // Parse the URL and get the hostname const urlObject = url.parse(urlString); const host = urlObject.hostname; @@ -28,4 +28,5 @@ const executeTraceroute = async (urlString, context) => { }; }; -exports.handler = middleware(executeTraceroute); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/txt-records.js b/api/txt-records.js index f397bc5..ed88dd7 100644 --- a/api/txt-records.js +++ b/api/txt-records.js @@ -29,4 +29,5 @@ const handler = async (url, event, context) => { } }; -exports.handler = middleware(handler); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); diff --git a/api/whois.js b/api/whois.js index 9cac306..7224b22 100644 --- a/api/whois.js +++ b/api/whois.js @@ -83,7 +83,7 @@ const fetchFromMyAPI = async (hostname) => { } }; -const fetchWhoisData = async (url) => { +const handler = async (url) => { if (!url.startsWith('http://') && !url.startsWith('https://')) { url = 'http://' + url; } @@ -106,4 +106,6 @@ const fetchWhoisData = async (url) => { }; }; -exports.handler = middleware(fetchWhoisData); +module.exports = middleware(handler); +module.exports.handler = middleware(handler); +