diff --git a/worker/src/monitor.ts b/worker/src/monitor.ts index e97d980..644d613 100644 --- a/worker/src/monitor.ts +++ b/worker/src/monitor.ts @@ -69,15 +69,18 @@ export async function getStatusWithGlobalPing( globalPingRequest = { type: 'ping', target: targetUrl.hostname, - locations: [ - { - magic: gpUrl.searchParams.get('magic') || '', - }, - ], + locations: + gpUrl.searchParams.get('magic') !== null + ? [ + { + magic: gpUrl.searchParams.get('magic'), + }, + ] + : undefined, measurementOptions: { port: targetUrl.port, packets: 1, - protocol: 'tcp', + protocol: 'tcp', // TODO: icmp? ipVersion: Number(gpUrl.searchParams.get('ipVersion') || 4), }, } @@ -92,11 +95,14 @@ export async function getStatusWithGlobalPing( globalPingRequest = { type: 'http', target: targetUrl.hostname, - locations: [ - { - magic: gpUrl.searchParams.get('magic') || '', - }, - ], + locations: + gpUrl.searchParams.get('magic') !== null + ? [ + { + magic: gpUrl.searchParams.get('magic'), + }, + ] + : undefined, measurementOptions: { request: { method: monitor.method, @@ -104,7 +110,7 @@ export async function getStatusWithGlobalPing( query: targetUrl.search === '' ? undefined : targetUrl.search, headers: Object.fromEntries( Object.entries(monitor.headers ?? {}).map(([key, value]) => [key, String(value)]) - ), // TODO: headers + ), // TODO: host header? }, port: targetUrl.port === '' diff --git a/worker/src/util.ts b/worker/src/util.ts index f9b33c3..b5249b2 100644 --- a/worker/src/util.ts +++ b/worker/src/util.ts @@ -68,7 +68,7 @@ function formatStatusChangeNotification( function templateWebhookPlayload(payload: any, message: string) { for (const key in payload) { - if (Object.prototype.hasOwnProperty.call(payload, key)) { + if (Object.prototype.hasOwnProperty.call(payload, key)) { if (payload[key] === '$MSG') { payload[key] = message } else if (typeof payload[key] === 'object' && payload[key] !== null) { @@ -86,7 +86,9 @@ async function webhookNotify(webhook: WebhookConfig, message: string) { let url = webhook.url let method = webhook.method let headers = new Headers(webhook.headers as any) - let payloadTemplated: { [key: string]: string | number } = JSON.parse(JSON.stringify(webhook.payload)) + let payloadTemplated: { [key: string]: string | number } = JSON.parse( + JSON.stringify(webhook.payload) + ) templateWebhookPlayload(payloadTemplated, message) let body = undefined