Update API endpoints to read URL params from either option

This commit is contained in:
Alicia Sykes 2023-07-28 21:46:20 +01:00
parent e2e16c9439
commit d03acb8a3c
22 changed files with 33 additions and 23 deletions

View File

@ -1,7 +1,7 @@
const https = require('https');
exports.handler = async function(event, context) {
const siteURL = event.queryStringParameters.url;
const siteURL = (event.queryStringParameters || event.query).url;
const errorResponse = (message, statusCode = 500) => {
return {

View File

@ -34,7 +34,7 @@ async function checkPort(port, domain) {
}
exports.handler = async (event, context) => {
const domain = event.queryStringParameters.url;
const domain = (event.queryStringParameters || event.query).url;
if (!domain) {
return errorResponse('Missing domain parameter.');

View File

@ -1,7 +1,7 @@
const https = require('https');
exports.handler = async function(event, context) {
let { url } = event.queryStringParameters;
const url = (event.queryStringParameters || event.query).url;
if (!url) {
return errorResponse('URL query parameter is required.');

View File

@ -4,7 +4,8 @@ const dnsPromises = dns.promises;
const axios = require('axios');
exports.handler = async (event) => {
const domain = event.queryStringParameters.url.replace(/^(?:https?:\/\/)?/i, "");
const url = (event.queryStringParameters || event.query).url;
const domain = url.replace(/^(?:https?:\/\/)?/i, "");
try {
const addresses = await dnsPromises.resolve4(domain);
const results = await Promise.all(addresses.map(async (address) => {

View File

@ -2,7 +2,7 @@ const dns = require('dns');
/* Lambda function to fetch the IP address of a given URL */
exports.handler = function (event, context, callback) {
const addressParam = event.queryStringParameters.url;
const addressParam = (event.queryStringParameters || event.query).url;
if (!addressParam) {
callback(null, errorResponse('Address parameter is missing.'));

View File

@ -1,5 +1,5 @@
exports.handler = async (event) => {
const { url } = event.queryStringParameters;
const url = (event.queryStringParameters || event.query).url;
const redirects = [url];
try {

View File

@ -1,7 +1,7 @@
const https = require('https');
exports.handler = async (event, context) => {
const { url } = event.queryStringParameters;
const url = (event.queryStringParameters || event.query).url;
if (!url) {
return {

View File

@ -1,7 +1,7 @@
const axios = require('axios');
exports.handler = async function(event, context) {
const { url } = event.queryStringParameters;
const url = (event.queryStringParameters || event.query).url;
if (!url) {
return {

View File

@ -2,7 +2,7 @@ const dns = require('dns');
const util = require('util');
exports.handler = async function(event, context) {
let hostname = event.queryStringParameters.url;
let hostname = (event.queryStringParameters || event.query).url;
// Handle URLs by extracting hostname
if (hostname.startsWith('http://') || hostname.startsWith('https://')) {

View File

@ -1,7 +1,7 @@
const axios = require('axios');
exports.handler = async function(event, context) {
const { url } = event.queryStringParameters;
const url = (event.queryStringParameters || event.query).url;
if (!url) {
return {

View File

@ -1,7 +1,15 @@
const dns = require('dns').promises;
exports.handler = async (event) => {
const url = new URL(event.queryStringParameters.url);
let url = (event.queryStringParameters || event.query).url;
try {
url = new URL(url);
} catch (error) {
return {
statusCode: 400,
body: JSON.stringify({ error: `Invalid URL ${error}` }),
};
}
try {
const txtRecords = await dns.resolveTxt(url.hostname);

View File

@ -1,7 +1,7 @@
const axios = require('axios');
exports.handler = function(event, context, callback) {
const { url } = event.queryStringParameters;
const url = (event.queryStringParameters || event.query).url;
if (!url) {
callback(null, {

View File

@ -1,7 +1,7 @@
const axios = require('axios');
exports.handler = async function(event, context) {
const siteURL = event.queryStringParameters.url;
const siteURL = (event.queryStringParameters || event.query).url;
if (!siteURL) {
return {

View File

@ -3,7 +3,7 @@ const chromium = require('chrome-aws-lambda');
exports.handler = async (event, context, callback) => {
let browser = null;
let targetUrl = event.queryStringParameters.url;
let targetUrl = (event.queryStringParameters || event.query).url;
if (!targetUrl) {
callback(null, {

View File

@ -38,7 +38,7 @@ const isPgpSigned = (result) => {
};
exports.handler = async (event, context) => {
const urlParam = event.queryStringParameters.url;
const urlParam = (event.queryStringParameters || event.query).url;
if (!urlParam) {
return {
statusCode: 400,

View File

@ -2,7 +2,7 @@ const https = require('https');
const { performance, PerformanceObserver } = require('perf_hooks');
exports.handler = async function(event, context) {
const { url } = event.queryStringParameters;
const url = (event.queryStringParameters || event.query).url;
if (!url) {
return {

View File

@ -1,7 +1,7 @@
const https = require('https');
exports.handler = async function (event, context) {
const { url } = event.queryStringParameters;
const url = (event.queryStringParameters || event.query).url;
const apiKey = process.env.BUILT_WITH_API_KEY;
const errorResponse = (message, statusCode = 500) => {

View File

@ -2,8 +2,9 @@ const axios = require('axios');
const xml2js = require('xml2js');
exports.handler = async (event) => {
const baseUrl = event.queryStringParameters.url.replace(/^(?:https?:\/\/)?/i, "");
const url = baseUrl.startsWith('http') ? baseUrl : `http://${baseUrl}`;
const url = (event.queryStringParameters || event.query).url;
// const baseUrl = event.queryStringParameters.url.replace(/^(?:https?:\/\/)?/i, "");
// const url = baseUrl.startsWith('http') ? baseUrl : `http://${baseUrl}`;
let sitemapUrl;
try {

View File

@ -1,7 +1,7 @@
const https = require('https');
exports.handler = async function (event, context) {
const { url } = event.queryStringParameters;
const url = (event.queryStringParameters || event.query).url;
const errorResponse = (message, statusCode = 500) => {
return {

View File

@ -34,7 +34,7 @@ exports.handler = async (event, context, callback) => {
}
// Get URL from param
let url = event.queryStringParameters.url;
let url = (event.queryStringParameters || event.query).url;
if (!/^https?:\/\//i.test(url)) {
url = 'http://' + url;
}

View File

@ -2,7 +2,7 @@ const traceroute = require('traceroute');
const url = require('url');
exports.handler = async function(event, context) {
const urlString = event.queryStringParameters.url;
const urlString = (event.queryStringParameters || event.query).url;
try {
if (!urlString) {

View File

@ -24,7 +24,7 @@ const getBaseDomain = (url) => {
exports.handler = async function(event, context) {
let url = event.queryStringParameters.url;
const url = (event.queryStringParameters || event.query).url;
if (!url) {
return errorResponse('URL query parameter is required.', 400);