Moves API handlers from server/lambda to /api

This commit is contained in:
Alicia Sykes 2023-07-22 17:53:33 +01:00
parent b81882e6cc
commit 8e1bc7a97e
24 changed files with 64 additions and 162 deletions

View File

@ -1,152 +1,39 @@
# Essential site config # Build settings and site core config
[build] [build]
base = "/" base = "/"
command = "yarn build" command = "yarn build"
publish = "build" publish = "build"
functions = "server/lambda" functions = "api"
# Environmental variables and optioanl secrets # Environmental variables and optioanl secrets
# [build.environment] [build.environment]
# NODE_VERSION = "16.16.0" # Build configuration env vars (uncomment if you want to conigure these)
# GOOGLE_CLOUD_API_KEY='' CI=false # Set CI to false, to prevent warnings from exiting the build
# SHODAN_API_KEY='' # CHROME_PATH='/usr/bin/chromium' # Path to Chromium binary
# REACT_APP_SHODAN_API_KEY='' # NODE_VERSION = "16.16.0" # Set the version of Node.js to use
# WHO_API_KEY=''
# REACT_APP_WHO_API_KEY=''
# SECURITY_TRAILS_API_KEY=''
# BUILT_WITH_API_KEY=''
# CI=false
# Site info, used for the 1-Click deploy page # Optional secrets and API keys (uncomment if you want to add these)
[template.environment] # GOOGLE_CLOUD_API_KEY='' # Google Cloud API key, for running Lighthouse scans
STATUSKIT_PAGE_TITLE = "Web Check" # BUILT_WITH_API_KEY='' # BuiltWith API key, for detecting site features
STATUSKIT_COMPANY_LOGO = "https://raw.githubusercontent.com/Lissy93/web-check/master/public/apple-touch-icon.png" # REACT_APP_SHODAN_API_KEY='' # Shodan API key, for using Shodan scan API
STATUSKIT_SUPPORT_CONTACT_LINK = "https://github.com/lissy93/web-check" # REACT_APP_WHO_API_KEY='' # WhoAPI key, for iniiating client-side whois lookup
# Redirect the Node endpoints to serverless functions # Redirect the /api/* path to the lambda functions
[[redirects]] [[redirects]]
from = "/find-url-ip" from = "/api/*"
to = "/.netlify/functions/find-url-ip" to = "/.netlify/functions/:splat"
status = 301
force = true
[[redirects]]
from = "/lighthouse-report"
to = "/.netlify/functions/lighthouse-report"
status = 301
force = true
[[redirects]]
from = "/ssl-check"
to = "/.netlify/functions/ssl-check"
status = 301
force = true
[[redirects]]
from = "/get-headers"
to = "/.netlify/functions/get-headers"
status = 301
force = true
[[redirects]]
from = "/get-cookies"
to = "/.netlify/functions/get-cookies"
status = 301
force = true
[[redirects]]
from = "/get-dns"
to = "/.netlify/functions/get-dns"
status = 301
force = true
[[redirects]]
from = "/read-robots-txt"
to = "/.netlify/functions/read-robots-txt"
status = 301
force = true
[[redirects]]
from = "/follow-redirects"
to = "/.netlify/functions/follow-redirects"
status = 301
force = true
[[redirects]]
from = "/get-txt"
to = "/.netlify/functions/get-txt"
status = 301
force = true
[[redirects]]
from = "/server-status"
to = "/.netlify/functions/server-status"
status = 301
force = true
[[redirects]]
from = "/check-ports"
to = "/.netlify/functions/check-ports"
status = 301
force = true
[[redirects]]
from = "/trace-route"
to = "/.netlify/functions/trace-route"
status = 301
force = true
[[redirects]]
from = "/get-carbon"
to = "/.netlify/functions/get-carbon"
status = 301
force = true
[[redirects]]
from = "/site-features"
to = "/.netlify/functions/site-features"
status = 301
force = true
[[redirects]]
from = "/dns-sec"
to = "/.netlify/functions/dns-sec"
status = 301
force = true
[[redirects]]
from = "/check-hsts"
to = "/.netlify/functions/check-hsts"
status = 301
force = true
[[redirects]]
from = "/whois-lookup"
to = "/.netlify/functions/whois-lookup"
status = 301
force = true
[[redirects]]
from = "/dns-server"
to = "/.netlify/functions/dns-server"
status = 301
force = true
[[redirects]]
from = "/tech-stack"
to = "/.netlify/functions/tech-stack"
status = 301
force = true
[[redirects]]
from = "/sitemap"
to = "/.netlify/functions/sitemap"
status = 301
force = true
[[redirects]]
from = "/screenshot"
to = "/.netlify/functions/screenshot"
status = 301 status = 301
force = true force = true
# Plugins
[[plugins]] [[plugins]]
package = "netlify-plugin-chromium" package = "netlify-plugin-chromium"
[plugins.inputs] [plugins.inputs]
packageManager = "yarn" packageManager = "yarn"
# For router history mode, ensure pages land on index
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
# Set any security headers here # Set any security headers here
[[headers]] [[headers]]
for = "/*" for = "/*"
[headers.values] [headers.values]
# Uncomment to enable Netlify user control. Requires premium plan. # Uncomment to enable Netlify user control. Requires premium plan.
# Basic-Auth = "someuser:somepassword anotheruser:anotherpassword" # Basic-Auth = "someuser:somepassword anotheruser:anotherpassword"

View File

@ -1,7 +1,26 @@
{ {
"name": "web-check", "name": "web-check",
"version": "0.1.0", "version": "1.0.0",
"private": true, "private": false,
"description": "All-in-one OSINT tool for analyzing any website",
"repository": "github:lissy93/web-check",
"homepage": "https://web-check.as93.net",
"license": "MIT",
"author": {
"name": "Alicia Sykes",
"email": "alicia@omg.lol"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/Lissy93"
},
"scripts": {
"dev": "netlify dev",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"dependencies": { "dependencies": {
"@netlify/functions": "^1.6.0", "@netlify/functions": "^1.6.0",
"@testing-library/jest-dom": "^5.17.0", "@testing-library/jest-dom": "^5.17.0",
@ -38,13 +57,6 @@
"web-vitals": "^3.4.0", "web-vitals": "^3.4.0",
"xml2js": "^0.6.0" "xml2js": "^0.6.0"
}, },
"scripts": {
"dev": "netlify dev",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [
"react-app", "react-app",

View File

@ -155,9 +155,10 @@ const Results = (): JSX.Element => {
response.json() response.json()
.then(data => resolve(data)) .then(data => resolve(data))
.catch(error => resolve( .catch(error => resolve(
{ error: `Failed to get a valid response 😢. { error: `Failed to get a valid response 😢\n`
This is likely due the target not exposing the required data, or limitations in how Netlify executes lambda functions, such as the 10-sec timeout. + `This is likely due the target not exposing the required data, `
Error info: ${error}`} + `or limitations in how Netlify executes lambda functions, such as the 10-sec timeout.\n\n`
+ `Error info:\n${error}`}
)); ));
}); });
}; };
@ -173,12 +174,14 @@ const Results = (): JSX.Element => {
const urlTypeOnly = ['url'] as AddressType[]; // Many jobs only run with these address types const urlTypeOnly = ['url'] as AddressType[]; // Many jobs only run with these address types
const api = '/api';
// Fetch and parse IP address for given URL // Fetch and parse IP address for given URL
const [ipAddress, setIpAddress] = useMotherHook({ const [ipAddress, setIpAddress] = useMotherHook({
jobId: 'get-ip', jobId: 'get-ip',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/find-url-ip?url=${address}`) fetchRequest: () => fetch(`${api}/find-url-ip?url=${address}`)
.then(res => parseJson(res)) .then(res => parseJson(res))
.then(res => res.ip), .then(res => res.ip),
}); });
@ -188,7 +191,7 @@ const Results = (): JSX.Element => {
jobId: 'ssl', jobId: 'ssl',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/ssl-check?url=${address}`).then((res) => parseJson(res)), fetchRequest: () => fetch(`${api}/ssl-check?url=${address}`).then((res) => parseJson(res)),
}); });
// Fetch and parse cookies info // Fetch and parse cookies info
@ -196,7 +199,7 @@ const Results = (): JSX.Element => {
jobId: 'cookies', jobId: 'cookies',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/get-cookies?url=${address}`) fetchRequest: () => fetch(`${api}/get-cookies?url=${address}`)
.then(res => parseJson(res)) .then(res => parseJson(res))
.then(res => parseCookies(res.cookies)), .then(res => parseCookies(res.cookies)),
}); });
@ -206,7 +209,7 @@ const Results = (): JSX.Element => {
jobId: 'robots-txt', jobId: 'robots-txt',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/read-robots-txt?url=${address}`) fetchRequest: () => fetch(`${api}/read-robots-txt?url=${address}`)
.then(res => res.text()) .then(res => res.text())
.then(res => parseRobotsTxt(res)), .then(res => parseRobotsTxt(res)),
}); });
@ -216,7 +219,7 @@ const Results = (): JSX.Element => {
jobId: 'headers', jobId: 'headers',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/get-headers?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/get-headers?url=${address}`).then(res => parseJson(res)),
}); });
// Fetch and parse DNS records // Fetch and parse DNS records
@ -224,7 +227,7 @@ const Results = (): JSX.Element => {
jobId: 'dns', jobId: 'dns',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/get-dns?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/get-dns?url=${address}`).then(res => parseJson(res)),
}); });
// Fetch and parse Lighthouse performance data // Fetch and parse Lighthouse performance data
@ -232,7 +235,7 @@ const Results = (): JSX.Element => {
jobId: 'quality', jobId: 'quality',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/lighthouse-report?url=${address}`) fetchRequest: () => fetch(`${api}/lighthouse-report?url=${address}`)
.then(res => parseJson(res)) .then(res => parseJson(res))
.then(res => res?.lighthouseResult || { error: 'No Data'}), .then(res => res?.lighthouseResult || { error: 'No Data'}),
}); });
@ -262,7 +265,7 @@ const Results = (): JSX.Element => {
jobId: 'ports', jobId: 'ports',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address: ipAddress, addressType: 'ipV4', expectedAddressTypes: ['ipV4', 'ipV6'] }, addressInfo: { address: ipAddress, addressType: 'ipV4', expectedAddressTypes: ['ipV4', 'ipV6'] },
fetchRequest: () => fetch(`/check-ports?url=${ipAddress}`) fetchRequest: () => fetch(`${api}/check-ports?url=${ipAddress}`)
.then(res => parseJson(res)), .then(res => parseJson(res)),
}); });
@ -281,7 +284,7 @@ const Results = (): JSX.Element => {
jobId: 'txt-records', jobId: 'txt-records',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/get-txt?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/get-txt?url=${address}`).then(res => parseJson(res)),
}); });
// Fetches URL redirects // Fetches URL redirects
@ -289,7 +292,7 @@ const Results = (): JSX.Element => {
jobId: 'redirects', jobId: 'redirects',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/follow-redirects?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/follow-redirects?url=${address}`).then(res => parseJson(res)),
}); });
// Get current status and response time of server // Get current status and response time of server
@ -297,7 +300,7 @@ const Results = (): JSX.Element => {
jobId: 'status', jobId: 'status',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/server-status?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/server-status?url=${address}`).then(res => parseJson(res)),
}); });
// Get current status and response time of server // Get current status and response time of server
@ -305,7 +308,7 @@ const Results = (): JSX.Element => {
jobId: 'tech-stack', jobId: 'tech-stack',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/tech-stack?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/tech-stack?url=${address}`).then(res => parseJson(res)),
}); });
// Get trace route for a given hostname // Get trace route for a given hostname
@ -313,7 +316,7 @@ const Results = (): JSX.Element => {
jobId: 'trace-route', jobId: 'trace-route',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/trace-route?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/trace-route?url=${address}`).then(res => parseJson(res)),
}); });
// Fetch carbon footprint data for a given site // Fetch carbon footprint data for a given site
@ -321,7 +324,7 @@ const Results = (): JSX.Element => {
jobId: 'carbon', jobId: 'carbon',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/get-carbon?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/get-carbon?url=${address}`).then(res => parseJson(res)),
}); });
// Check if a site is on the HSTS preload list // Check if a site is on the HSTS preload list
@ -329,7 +332,7 @@ const Results = (): JSX.Element => {
jobId: 'hsts', jobId: 'hsts',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/check-hsts?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/check-hsts?url=${address}`).then(res => parseJson(res)),
}); });
// Get a websites listed pages, from sitemap // Get a websites listed pages, from sitemap
@ -337,7 +340,7 @@ const Results = (): JSX.Element => {
jobId: 'sitemap', jobId: 'sitemap',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/sitemap?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/sitemap?url=${address}`).then(res => parseJson(res)),
}); });
// Get a websites listed pages, from sitemap // Get a websites listed pages, from sitemap
@ -345,7 +348,7 @@ const Results = (): JSX.Element => {
jobId: 'screenshot', jobId: 'screenshot',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/screenshot?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/screenshot?url=${address}`).then(res => parseJson(res)),
}); });
// Get site features from BuiltWith // Get site features from BuiltWith
@ -353,7 +356,7 @@ const Results = (): JSX.Element => {
jobId: 'features', jobId: 'features',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/site-features?url=${address}`) fetchRequest: () => fetch(`${api}/site-features?url=${address}`)
.then(res => parseJson(res)) .then(res => parseJson(res))
.then(res => { .then(res => {
if (res.Errors && res.Errors.length > 0) { if (res.Errors && res.Errors.length > 0) {
@ -368,7 +371,7 @@ const Results = (): JSX.Element => {
jobId: 'dnssec', jobId: 'dnssec',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/dns-sec?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/dns-sec?url=${address}`).then(res => parseJson(res)),
}); });
// Run a manual whois lookup on the domain // Run a manual whois lookup on the domain
@ -376,7 +379,7 @@ const Results = (): JSX.Element => {
jobId: 'domain', jobId: 'domain',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/whois-lookup?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/whois-lookup?url=${address}`).then(res => parseJson(res)),
}); });
// Get the DNS server(s) for a domain, and test DoH/DoT support // Get the DNS server(s) for a domain, and test DoH/DoT support
@ -384,7 +387,7 @@ const Results = (): JSX.Element => {
jobId: 'dns-server', jobId: 'dns-server',
updateLoadingJobs, updateLoadingJobs,
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
fetchRequest: () => fetch(`/dns-server?url=${address}`).then(res => parseJson(res)), fetchRequest: () => fetch(`${api}/dns-server?url=${address}`).then(res => parseJson(res)),
}); });
/* Cancel remaining jobs after 10 second timeout */ /* Cancel remaining jobs after 10 second timeout */