SHOULD WORK: worker support proxy
parent
c248bddf1c
commit
8b07dfe30e
|
|
@ -54,9 +54,11 @@ const workerConfig = {
|
||||||
responseKeyword: 'success',
|
responseKeyword: 'success',
|
||||||
// [OPTIONAL] if specified, the response must NOT contains the keyword to be considered as operational.
|
// [OPTIONAL] if specified, the response must NOT contains the keyword to be considered as operational.
|
||||||
responseForbiddenKeyword: 'bad gateway',
|
responseForbiddenKeyword: 'bad gateway',
|
||||||
// [OPTIONAL] if specified, the check will run in your specified region,
|
// [OPTIONAL] if specified, will call the check proxy to check the monitor, mainly for geo-specific checks
|
||||||
// refer to docs https://github.com/lyc8503/UptimeFlare/wiki/Geo-specific-checks-setup before setting this value
|
// refer to docs **TODO** before setting this value
|
||||||
checkLocationWorkerRoute: 'https://xxx.example.com',
|
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
|
// Example TCP Monitor
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,9 @@ type MonitorTarget = {
|
||||||
target: string // url for http, hostname:port for tcp
|
target: string // url for http, hostname:port for tcp
|
||||||
tooltip?: string
|
tooltip?: string
|
||||||
statusPageLink?: string
|
statusPageLink?: string
|
||||||
checkLocationWorkerRoute?: string
|
|
||||||
hideLatencyChart?: boolean
|
hideLatencyChart?: boolean
|
||||||
|
checkProxy?: string
|
||||||
|
checkProxyFallback?: boolean
|
||||||
|
|
||||||
// HTTP Code
|
// HTTP Code
|
||||||
expectedCodes?: number[]
|
expectedCodes?: number[]
|
||||||
|
|
|
||||||
|
|
@ -106,23 +106,27 @@ export default {
|
||||||
let checkLocation = workerLocation
|
let checkLocation = workerLocation
|
||||||
let status
|
let status
|
||||||
|
|
||||||
if (monitor.checkLocationWorkerRoute) {
|
if (monitor.checkProxy) {
|
||||||
// Initiate a check from a different location
|
// Initiate a check using proxy (Geo-specific check)
|
||||||
try {
|
try {
|
||||||
console.log('Calling worker: ' + monitor.checkLocationWorkerRoute)
|
console.log('Calling check proxy: ' + monitor.checkProxy)
|
||||||
const resp = await (
|
const resp = await (
|
||||||
await fetch(monitor.checkLocationWorkerRoute, {
|
await fetch(monitor.checkProxy, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
headers: { 'Content-Type': 'application/json' },
|
||||||
target: monitor.id,
|
body: JSON.stringify(monitor),
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
).json<{ location: string; status: { ping: number; up: boolean; err: string } }>()
|
).json<{ location: string; status: { ping: number; up: boolean; err: string } }>()
|
||||||
checkLocation = resp.location
|
checkLocation = resp.location
|
||||||
status = resp.status
|
status = resp.status
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('Error calling worker: ' + err)
|
console.log('Error calling proxy: ' + err)
|
||||||
status = { ping: 0, up: false, err: 'Error initiating check from remote worker' }
|
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 {
|
} else {
|
||||||
// Initiate a check from the current location
|
// Initiate a check from the current location
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue