From c9e57400fdf35d733d198fb46ef726c126e52ac1 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Mon, 6 May 2024 21:51:32 +0100 Subject: [PATCH] Convert all API endpoints into ESM modules --- api/_common/middleware.js | 2 +- api/archives.js | 10 +++++----- api/block-lists.js | 12 ++++++------ api/carbon.js | 10 +++++----- api/cookies.js | 12 ++++++------ api/dns-server.js | 15 ++++++++------- api/dns.js | 12 ++++++------ api/dnssec.js | 10 +++++----- api/features.js | 10 +++++----- api/firewall.js | 10 +++++----- api/get-ip.js | 10 +++++----- api/headers.js | 10 +++++----- api/hsts.js | 11 +++++------ api/http-security.js | 10 +++++----- api/legacy-rank.js | 17 ++++++++--------- api/linked-pages.js | 14 +++++++------- api/mail-config.js | 13 ++++++------- api/ports.js | 10 +++++----- api/quality.js | 10 +++++----- api/rank.js | 10 +++++----- api/redirects.js | 15 +++++++-------- api/robots-txt.js | 10 +++++----- api/screenshot.js | 12 ++++++------ api/security-txt.js | 14 ++++++++------ api/sitemap.js | 13 ++++++------- api/social-tags.js | 13 ++++++------- api/ssl.js | 10 +++++----- api/status.js | 12 ++++++------ api/tech-stack.js | 10 +++++----- api/threats.js | 12 ++++++------ api/tls.js | 10 +++++----- api/trace-route.js | 12 ++++++------ api/txt-records.js | 10 +++++----- api/whois.js | 14 +++++++------- 34 files changed, 191 insertions(+), 194 deletions(-) diff --git a/api/_common/middleware.js b/api/_common/middleware.js index 6eb4ca9..b6de8a2 100644 --- a/api/_common/middleware.js +++ b/api/_common/middleware.js @@ -124,4 +124,4 @@ const commonMiddleware = (handler) => { return nativeMode ? vercelHandler : netlifyHandler; }; -module.exports = commonMiddleware; +export default commonMiddleware; diff --git a/api/archives.js b/api/archives.js index 6c7cb48..7c6ae99 100644 --- a/api/archives.js +++ b/api/archives.js @@ -1,5 +1,5 @@ -const axios = require('axios'); -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import middleware from './_common/middleware.js'; const convertTimestampToDate = (timestamp) => { const [year, month, day, hour, minute, second] = [ @@ -46,7 +46,7 @@ const getScanFrequency = (firstScan, lastScan, totalScans, changeCount) => { }; }; -const getWaybackData = async (url) => { +const wayBackHandler = async (url) => { const cdxUrl = `https://web.archive.org/cdx/search/cdx?url=${url}&output=json&fl=timestamp,statuscode,digest,length,offset`; try { @@ -80,5 +80,5 @@ const getWaybackData = async (url) => { } }; -module.exports = middleware(getWaybackData); -module.exports.handler = middleware(getWaybackData); +export const handler = middleware(wayBackHandler); +export default handler; diff --git a/api/block-lists.js b/api/block-lists.js index 82f6b1c..34d46a1 100644 --- a/api/block-lists.js +++ b/api/block-lists.js @@ -1,6 +1,6 @@ -const dns = require('dns'); -const { URL } = require('url'); -const middleware = require('./_common/middleware'); +import dns from 'dns'; +import { URL } from 'url'; +import middleware from './_common/middleware.js'; const DNS_SERVERS = [ { name: 'AdGuard', ip: '176.103.130.130' }, @@ -94,12 +94,12 @@ const checkDomainAgainstDnsServers = async (domain) => { return results; }; -const handler = async (url) => { +export const blockListHandler = async (url) => { const domain = new URL(url).hostname; const results = await checkDomainAgainstDnsServers(domain); return { blocklists: results }; }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(blockListHandler); +export default handler; diff --git a/api/carbon.js b/api/carbon.js index a2c5210..7db750c 100644 --- a/api/carbon.js +++ b/api/carbon.js @@ -1,7 +1,7 @@ -const https = require('https'); -const middleware = require('./_common/middleware'); +import https from 'https'; +import middleware from './_common/middleware.js'; -const handler = async (url) => { +const carbonHandler = async (url) => { // First, get the size of the website's HTML const getHtmlSize = (url) => new Promise((resolve, reject) => { @@ -48,5 +48,5 @@ const handler = async (url) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(carbonHandler); +export default handler; diff --git a/api/cookies.js b/api/cookies.js index 1f10470..a86ccb6 100644 --- a/api/cookies.js +++ b/api/cookies.js @@ -1,6 +1,6 @@ -const axios = require('axios'); -const puppeteer = require('puppeteer'); -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import puppeteer from 'puppeteer'; +import middleware from './_common/middleware.js'; const getPuppeteerCookies = async (url) => { const browser = await puppeteer.launch({ @@ -21,7 +21,7 @@ const getPuppeteerCookies = async (url) => { } }; -const handler = async (url) => { +const cookieHandler = async (url) => { let headerCookies = null; let clientCookies = null; @@ -54,5 +54,5 @@ const handler = async (url) => { return { headerCookies, clientCookies }; }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(cookieHandler); +export default handler; diff --git a/api/dns-server.js b/api/dns-server.js index c9af720..29ac34f 100644 --- a/api/dns-server.js +++ b/api/dns-server.js @@ -1,9 +1,8 @@ -const dns = require('dns'); -const dnsPromises = dns.promises; -const axios = require('axios'); -const middleware = require('./_common/middleware'); +import { promises as dnsPromises, lookup } from 'dns'; +import axios from 'axios'; +import middleware from './_common/middleware.js'; -const handler = async (url) => { +const dnsHandler = async (url) => { try { const domain = url.replace(/^(?:https?:\/\/)?/i, ""); const addresses = await dnsPromises.resolve4(domain); @@ -41,5 +40,7 @@ const handler = async (url) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); + +export const handler = middleware(dnsHandler); +export default handler; + diff --git a/api/dns.js b/api/dns.js index 34d6c02..e01a8a8 100644 --- a/api/dns.js +++ b/api/dns.js @@ -1,8 +1,8 @@ -const dns = require('dns'); -const util = require('util'); -const middleware = require('./_common/middleware'); +import dns from 'dns'; +import util from 'util'; +import middleware from './_common/middleware.js'; -const handler = async (url) => { +const dnsHandler = async (url) => { let hostname = url; // Handle URLs by extracting hostname @@ -51,5 +51,5 @@ const handler = async (url) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(dnsHandler); +export default handler; diff --git a/api/dnssec.js b/api/dnssec.js index afaa955..21f7510 100644 --- a/api/dnssec.js +++ b/api/dnssec.js @@ -1,7 +1,7 @@ -const https = require('https'); -const middleware = require('./_common/middleware'); // Make sure this path is correct +import https from 'https'; +import middleware from './_common/middleware.js'; -const handler = async (domain) => { +const dnsSecHandler = async (domain) => { const dnsTypes = ['DNSKEY', 'DS', 'RRSIG']; const records = {}; @@ -53,5 +53,5 @@ const handler = async (domain) => { return records; }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); \ No newline at end of file +export const handler = middleware(dnsSecHandler); +export default handler; diff --git a/api/features.js b/api/features.js index 67e4c81..148a854 100644 --- a/api/features.js +++ b/api/features.js @@ -1,7 +1,7 @@ -const https = require('https'); -const middleware = require('./_common/middleware'); +import https from 'https'; +import middleware from './_common/middleware.js'; -const handler = async (url) => { +const featuresHandler = async (url) => { const apiKey = process.env.BUILT_WITH_API_KEY; if (!url) { @@ -45,5 +45,5 @@ const handler = async (url) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(featuresHandler); +export default handler; diff --git a/api/firewall.js b/api/firewall.js index 39afde3..3588c33 100644 --- a/api/firewall.js +++ b/api/firewall.js @@ -1,5 +1,5 @@ -const axios = require('axios'); -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import middleware from './_common/middleware.js'; const hasWaf = (waf) => { return { @@ -7,7 +7,7 @@ const hasWaf = (waf) => { } }; -const handler = async (url) => { +const firewallHandler = async (url) => { const fullUrl = url.startsWith('http') ? url : `http://${url}`; try { @@ -102,5 +102,5 @@ const handler = async (url) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(firewallHandler); +export default handler; diff --git a/api/get-ip.js b/api/get-ip.js index 303a0f1..aa7d058 100644 --- a/api/get-ip.js +++ b/api/get-ip.js @@ -1,5 +1,5 @@ -const dns = require('dns'); -const middleware = require('./_common/middleware'); +import dns from 'dns'; +import middleware from './_common/middleware.js'; const lookupAsync = (address) => { return new Promise((resolve, reject) => { @@ -13,11 +13,11 @@ const lookupAsync = (address) => { }); }; -const handler = async (url) => { +const ipHandler = async (url) => { const address = url.replaceAll('https://', '').replaceAll('http://', ''); return await lookupAsync(address); }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(ipHandler); +export default handler; diff --git a/api/headers.js b/api/headers.js index 84b179f..13c2792 100644 --- a/api/headers.js +++ b/api/headers.js @@ -1,7 +1,7 @@ -const axios = require('axios'); -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import middleware from './_common/middleware.js'; -const handler = async (url, event, context) => { +const headersHandler = async (url, event, context) => { try { const response = await axios.get(url, { validateStatus: function (status) { @@ -15,5 +15,5 @@ const handler = async (url, event, context) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(headersHandler); +export default handler; diff --git a/api/hsts.js b/api/hsts.js index d06bf1c..a98d4c0 100644 --- a/api/hsts.js +++ b/api/hsts.js @@ -1,7 +1,7 @@ -const https = require('https'); -const middleware = require('./_common/middleware'); +import https from 'https'; +import middleware from './_common/middleware.js'; -const handler = async (url, event, context) => { +const hstsHandler = async (url, event, context) => { const errorResponse = (message, statusCode = 500) => { return { statusCode: statusCode, @@ -45,6 +45,5 @@ const handler = async (url, event, context) => { }); }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); - +export const handler = middleware(hstsHandler); +export default handler; diff --git a/api/http-security.js b/api/http-security.js index 2f8370a..764cb93 100644 --- a/api/http-security.js +++ b/api/http-security.js @@ -1,7 +1,7 @@ -const axios = require('axios'); -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import middleware from './_common/middleware.js'; -const handler = async (url) => { +const httpsSecHandler = async (url) => { const fullUrl = url.startsWith('http') ? url : `http://${url}`; try { @@ -22,5 +22,5 @@ const handler = async (url) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(httpsSecHandler); +export default handler; diff --git a/api/legacy-rank.js b/api/legacy-rank.js index 19dd1bd..301cc2c 100644 --- a/api/legacy-rank.js +++ b/api/legacy-rank.js @@ -1,8 +1,8 @@ -const axios = require('axios'); -const unzipper = require('unzipper'); -const csv = require('csv-parser'); -const fs = require('fs'); -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import unzipper from 'unzipper'; +import csv from 'csv-parser'; +import fs from 'fs'; +import middleware from './_common/middleware.js'; // Should also work with the following sources: // https://www.domcop.com/files/top/top10milliondomains.csv.zip @@ -14,7 +14,7 @@ const middleware = require('./_common/middleware'); const FILE_URL = 'https://s3-us-west-1.amazonaws.com/umbrella-static/top-1m.csv.zip'; const TEMP_FILE_PATH = '/tmp/top-1m.csv'; -const handler = async (url) => { +const rankHandler = async (url) => { let domain = null; try { @@ -66,6 +66,5 @@ return new Promise((resolve, reject) => { }); }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); - +export const handler = middleware(rankHandler); +export default handler; diff --git a/api/linked-pages.js b/api/linked-pages.js index 60dd88f..750d54f 100644 --- a/api/linked-pages.js +++ b/api/linked-pages.js @@ -1,9 +1,9 @@ -const axios = require('axios'); -const cheerio = require('cheerio'); -const urlLib = require('url'); -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import cheerio from 'cheerio'; +import urlLib from 'url'; +import middleware from './_common/middleware.js'; -const handler = async (url) => { +const linkedPagesHandler = async (url) => { const response = await axios.get(url); const html = response.data; const $ = cheerio.load(html); @@ -45,5 +45,5 @@ const handler = async (url) => { return { internal: internalLinks, external: externalLinks }; }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(linkedPagesHandler); +export default handler; diff --git a/api/mail-config.js b/api/mail-config.js index 402fd67..0d430f9 100644 --- a/api/mail-config.js +++ b/api/mail-config.js @@ -1,9 +1,8 @@ -const middleware = require('./_common/middleware'); +import dns from 'dns'; +import URL from 'url-parse'; +import middleware from './_common/middleware.js'; -const dns = require('dns').promises; -const URL = require('url-parse'); - -const handler = async (url, event, context) => { +const mailConfigHandler = async (url, event, context) => { try { const domain = new URL(url).hostname || new URL(url).pathname; @@ -77,5 +76,5 @@ const handler = async (url, event, context) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(mailConfigHandler); +export default handler; diff --git a/api/ports.js b/api/ports.js index 63e2c25..c302293 100644 --- a/api/ports.js +++ b/api/ports.js @@ -1,5 +1,5 @@ -const net = require('net'); -const middleware = require('./_common/middleware'); +import net from 'net'; +import middleware from './_common/middleware.js'; // A list of commonly used ports. const PORTS = [ @@ -34,7 +34,7 @@ async function checkPort(port, domain) { }); } -const handler = async (url, event, context) => { +const portsHandler = async (url, event, context) => { const domain = url.replace(/(^\w+:|^)\/\//, ''); const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -80,5 +80,5 @@ const errorResponse = (message, statusCode = 444) => { return { error: message }; }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(portsHandler); +export default handler; diff --git a/api/quality.js b/api/quality.js index a49afe1..1d123c1 100644 --- a/api/quality.js +++ b/api/quality.js @@ -1,7 +1,7 @@ -const axios = require('axios'); -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import middleware from './_common/middleware.js'; -const handler = async (url, event, context) => { +const qualityHandler = async (url, event, context) => { const apiKey = process.env.GOOGLE_CLOUD_API_KEY; if (!apiKey) { @@ -18,5 +18,5 @@ const handler = async (url, event, context) => { return (await axios.get(endpoint)).data; }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(qualityHandler); +export default handler; diff --git a/api/rank.js b/api/rank.js index 1947185..d2936ee 100644 --- a/api/rank.js +++ b/api/rank.js @@ -1,7 +1,7 @@ -const axios = require('axios'); -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import middleware from './_common/middleware.js'; -const handler = async (url) => { +const rankHandler = async (url) => { const domain = url ? new URL(url).hostname : null; if (!domain) throw new Error('Invalid URL'); @@ -21,6 +21,6 @@ const handler = async (url) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(rankHandler); +export default handler; diff --git a/api/redirects.js b/api/redirects.js index cd815b1..af7016e 100644 --- a/api/redirects.js +++ b/api/redirects.js @@ -1,9 +1,10 @@ -const handler = async (url) => { - const redirects = [url]; - const got = await import('got'); +import got from 'got'; +import middleware from './_common/middleware.js'; +const redirectsHandler = async (url) => { + const redirects = [url]; try { - await got.default(url, { + await got(url, { followRedirect: true, maxRedirects: 12, hooks: { @@ -23,7 +24,5 @@ const handler = async (url) => { } }; -const middleware = require('./_common/middleware'); - -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(redirectsHandler); +export default handler; diff --git a/api/robots-txt.js b/api/robots-txt.js index 9f008e3..afe6f52 100644 --- a/api/robots-txt.js +++ b/api/robots-txt.js @@ -1,5 +1,5 @@ -const axios = require('axios'); -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import middleware from './_common/middleware.js'; const parseRobotsTxt = (content) => { const lines = content.split('\n'); @@ -31,7 +31,7 @@ const parseRobotsTxt = (content) => { return { robots: rules }; } -const handler = async function(url) { +const robotsHandler = async function(url) { let parsedURL; try { parsedURL = new URL(url); @@ -67,5 +67,5 @@ const handler = async function(url) { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(robotsHandler); +export default handler; diff --git a/api/screenshot.js b/api/screenshot.js index 9345f14..f6d33bf 100644 --- a/api/screenshot.js +++ b/api/screenshot.js @@ -1,8 +1,8 @@ -const puppeteer = require('puppeteer-core'); -const chromium = require('chrome-aws-lambda'); -const middleware = require('./_common/middleware'); +import puppeteer from 'puppeteer-core'; +import chromium from 'chrome-aws-lambda'; +import middleware from './_common/middleware.js'; -const handler = async (targetUrl) => { +const screenshotHandler = async (targetUrl) => { if (!targetUrl) { throw new Error('URL is missing from queryStringParameters'); @@ -58,5 +58,5 @@ const handler = async (targetUrl) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(screenshotHandler); +export default handler; diff --git a/api/security-txt.js b/api/security-txt.js index dd08ca0..08cdcff 100644 --- a/api/security-txt.js +++ b/api/security-txt.js @@ -1,6 +1,8 @@ -const { https } = require('follow-redirects'); -const { URL } = require('url'); -const middleware = require('./_common/middleware'); +import { URL } from 'url'; +import followRedirects from 'follow-redirects'; +import middleware from './_common/middleware.js'; + +const { https } = followRedirects; const SECURITY_TXT_PATHS = [ '/security.txt', @@ -38,7 +40,7 @@ const isPgpSigned = (result) => { return false; }; -const handler = async (urlParam) => { +const securityTxtHandler = async (urlParam) => { let url; try { @@ -90,5 +92,5 @@ async function fetchSecurityTxt(baseURL, path) { }); } -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(securityTxtHandler); +export default handler; diff --git a/api/sitemap.js b/api/sitemap.js index 4d6c01d..282bf77 100644 --- a/api/sitemap.js +++ b/api/sitemap.js @@ -1,9 +1,8 @@ -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import xml2js from 'xml2js'; +import middleware from './_common/middleware.js'; -const axios = require('axios'); -const xml2js = require('xml2js'); - -const handler = async (url) => { +const sitemapHandler = async (url) => { let sitemapUrl = `${url}/sitemap.xml`; const hardTimeOut = 5000; @@ -49,6 +48,6 @@ const handler = async (url) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(sitemapHandler); +export default handler; diff --git a/api/social-tags.js b/api/social-tags.js index f8b38a3..e2c6bb4 100644 --- a/api/social-tags.js +++ b/api/social-tags.js @@ -1,9 +1,8 @@ -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import cheerio from 'cheerio'; +import middleware from './_common/middleware.js'; -const axios = require('axios'); -const cheerio = require('cheerio'); - -const handler = async (url) => { +const socialTagsHandler = async (url) => { // Check if url includes protocol if (!url.startsWith('http://') && !url.startsWith('https://')) { @@ -61,5 +60,5 @@ const handler = async (url) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(socialTagsHandler); +export default handler; diff --git a/api/ssl.js b/api/ssl.js index 1eb5c55..6f58be0 100644 --- a/api/ssl.js +++ b/api/ssl.js @@ -1,7 +1,7 @@ -const tls = require('tls'); -const middleware = require('./_common/middleware'); +import tls from 'tls'; +import middleware from './_common/middleware.js'; -const handler = async (urlString) => { +const sslHandler = async (urlString) => { try { const parsedUrl = new URL(urlString); const options = { @@ -40,5 +40,5 @@ const handler = async (urlString) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(sslHandler); +export default handler; diff --git a/api/status.js b/api/status.js index 2a70b66..0fcc578 100644 --- a/api/status.js +++ b/api/status.js @@ -1,8 +1,8 @@ -const https = require('https'); -const { performance, PerformanceObserver } = require('perf_hooks'); -const middleware = require('./_common/middleware'); +import https from 'https'; +import { performance, PerformanceObserver } from 'perf_hooks'; +import middleware from './_common/middleware.js'; -const handler = async (url) => { +const statusHandler = async (url) => { if (!url) { throw new Error('You must provide a URL query parameter!'); } @@ -55,5 +55,5 @@ const handler = async (url) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(statusHandler); +export default handler; diff --git a/api/tech-stack.js b/api/tech-stack.js index d649d2b..dcf0b8a 100644 --- a/api/tech-stack.js +++ b/api/tech-stack.js @@ -1,7 +1,7 @@ -const Wappalyzer = require('wappalyzer'); -const middleware = require('./_common/middleware'); +import Wappalyzer from 'wappalyzer'; +import middleware from './_common/middleware.js'; -const handler = async (url) => { +const techStackHandler = async (url) => { const options = {}; const wappalyzer = new Wappalyzer(options); @@ -27,5 +27,5 @@ const handler = async (url) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(techStackHandler); +export default handler; diff --git a/api/threats.js b/api/threats.js index afff98c..de95932 100644 --- a/api/threats.js +++ b/api/threats.js @@ -1,6 +1,6 @@ -const axios = require('axios'); -const xml2js = require('xml2js'); -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import xml2js from 'xml2js'; +import middleware from './_common/middleware.js'; const getGoogleSafeBrowsingResult = async (url) => { try { @@ -84,7 +84,7 @@ const getCloudmersiveResult = async (url) => { } }; -const handler = async (url) => { +const threatsHandler = async (url) => { try { const urlHaus = await getUrlHausResult(url); const phishTank = await getPhishTankResult(url); @@ -99,5 +99,5 @@ const handler = async (url) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(threatsHandler); +export default handler; diff --git a/api/tls.js b/api/tls.js index 09aeaeb..7d5a117 100644 --- a/api/tls.js +++ b/api/tls.js @@ -1,9 +1,9 @@ -const axios = require('axios'); -const middleware = require('./_common/middleware'); +import axios from 'axios'; +import middleware from './_common/middleware.js'; const MOZILLA_TLS_OBSERVATORY_API = 'https://tls-observatory.services.mozilla.com/api/v1'; -const handler = async (url) => { +const tlsHandler = async (url) => { try { const domain = new URL(url).hostname; const scanResponse = await axios.post(`${MOZILLA_TLS_OBSERVATORY_API}/scan?target=${domain}`); @@ -25,5 +25,5 @@ const handler = async (url) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(tlsHandler); +export default handler; diff --git a/api/trace-route.js b/api/trace-route.js index 2b71e48..50cd3b1 100644 --- a/api/trace-route.js +++ b/api/trace-route.js @@ -1,8 +1,8 @@ -const traceroute = require('traceroute'); -const url = require('url'); -const middleware = require('./_common/middleware'); +import url from 'url'; +import traceroute from 'traceroute'; +import middleware from './_common/middleware.js'; -const handler = async (urlString, context) => { +const traceRouteHandler = async (urlString, context) => { // Parse the URL and get the hostname const urlObject = url.parse(urlString); const host = urlObject.hostname; @@ -28,5 +28,5 @@ const handler = async (urlString, context) => { }; }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(traceRouteHandler); +export default handler; diff --git a/api/txt-records.js b/api/txt-records.js index ed88dd7..73104f1 100644 --- a/api/txt-records.js +++ b/api/txt-records.js @@ -1,7 +1,7 @@ -const dns = require('dns').promises; -const middleware = require('./_common/middleware'); +import dns from 'dns/promises'; +import middleware from './_common/middleware.js'; -const handler = async (url, event, context) => { +const txtRecordHandler = async (url, event, context) => { try { const parsedUrl = new URL(url); @@ -29,5 +29,5 @@ const handler = async (url, event, context) => { } }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(txtRecordHandler); +export default handler; diff --git a/api/whois.js b/api/whois.js index 7224b22..8daba8a 100644 --- a/api/whois.js +++ b/api/whois.js @@ -1,7 +1,7 @@ -const net = require('net'); -const psl = require('psl'); -const axios = require('axios'); -const middleware = require('./_common/middleware'); +import net from 'net'; +import psl from 'psl'; +import axios from 'axios'; +import middleware from './_common/middleware.js'; const getBaseDomain = (url) => { let protocol = ''; @@ -83,7 +83,7 @@ const fetchFromMyAPI = async (hostname) => { } }; -const handler = async (url) => { +const whoisHandler = async (url) => { if (!url.startsWith('http://') && !url.startsWith('https://')) { url = 'http://' + url; } @@ -106,6 +106,6 @@ const handler = async (url) => { }; }; -module.exports = middleware(handler); -module.exports.handler = middleware(handler); +export const handler = middleware(whoisHandler); +export default handler;