SHOULD WORK: worker support proxy

pull/97/merge
lyc8503 2025-04-11 01:29:46 +08:00
parent c248bddf1c
commit 8b07dfe30e
3 changed files with 20 additions and 13 deletions

View File

@ -54,9 +54,11 @@ const workerConfig = {
responseKeyword: 'success',
// [OPTIONAL] if specified, the response must NOT contains the keyword to be considered as operational.
responseForbiddenKeyword: 'bad gateway',
// [OPTIONAL] if specified, the check will run in your specified region,
// refer to docs https://github.com/lyc8503/UptimeFlare/wiki/Geo-specific-checks-setup before setting this value
checkLocationWorkerRoute: 'https://xxx.example.com',
// [OPTIONAL] if specified, will call the check proxy to check the monitor, mainly for geo-specific checks
// refer to docs **TODO** before setting this value
checkProxy: 'https://xxx.example.com',
// [OPTIONAL] if true, the check will fallback to local if the specified proxy is down
checkProxyFallback: true,
},
// Example TCP Monitor
{

View File

@ -35,8 +35,9 @@ type MonitorTarget = {
target: string // url for http, hostname:port for tcp
tooltip?: string
statusPageLink?: string
checkLocationWorkerRoute?: string
hideLatencyChart?: boolean
checkProxy?: string
checkProxyFallback?: boolean
// HTTP Code
expectedCodes?: number[]

View File

@ -106,23 +106,27 @@ export default {
let checkLocation = workerLocation
let status
if (monitor.checkLocationWorkerRoute) {
// Initiate a check from a different location
if (monitor.checkProxy) {
// Initiate a check using proxy (Geo-specific check)
try {
console.log('Calling worker: ' + monitor.checkLocationWorkerRoute)
console.log('Calling check proxy: ' + monitor.checkProxy)
const resp = await (
await fetch(monitor.checkLocationWorkerRoute, {
await fetch(monitor.checkProxy, {
method: 'POST',
body: JSON.stringify({
target: monitor.id,
}),
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(monitor),
})
).json<{ location: string; status: { ping: number; up: boolean; err: string } }>()
checkLocation = resp.location
status = resp.status
} catch (err) {
console.log('Error calling worker: ' + err)
status = { ping: 0, up: false, err: 'Error initiating check from remote worker' }
console.log('Error calling proxy: ' + err)
if (monitor.checkProxyFallback) {
console.log('Falling back to local check...')
status = await getStatus(monitor)
} else {
status = { ping: 0, up: false, err: 'Error initiating check from remote worker' }
}
}
} else {
// Initiate a check from the current location