From 7322f7c7f5592617101e5ea7c7dd60a336a0a8d1 Mon Sep 17 00:00:00 2001 From: Yury Date: Mon, 27 May 2024 17:46:06 +0300 Subject: [PATCH] fix(RelayInfo): fixed handling relays with outdated certificates --- src/job-types/relay-info.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/job-types/relay-info.ts b/src/job-types/relay-info.ts index 2b44828..dc871db 100644 --- a/src/job-types/relay-info.ts +++ b/src/job-types/relay-info.ts @@ -2,6 +2,7 @@ import { NDKEvent } from '@nostr-dev-kit/ndk' import { log } from '../main.js' import axios from 'axios' import { RelayInfo } from '../types/index.js' +import https from 'https' export const relayInfoJob = async (event: NDKEvent): Promise => { log('New relay-info job', event.rawEvent()) @@ -22,8 +23,15 @@ export const relayInfoJob = async (event: NDKEvent): Promise => { } const prefixes = { wss: 'wss://', https: 'https://', http: 'http://' } - const headers = { - headers: { Accept: 'application/nostr+json' } + + // Relay may have outdated certificate 'rejectUnauthorized: false' will prevent + // throwing ann error on request + const agent = new https.Agent({ + rejectUnauthorized: false + }) + const config = { + headers: { Accept: 'application/nostr+json' }, + httpsAgent: agent } const requests = relays.map((relay) => { @@ -32,12 +40,12 @@ export const relayInfoJob = async (event: NDKEvent): Promise => { } return axios - .get((relay = `${prefixes.https}${relay}`), headers) - .catch(() => { - return axios - .get(`${prefixes.http}${relay}`, headers) + .get((relay = `${prefixes.https}${relay}`), config) + .catch(() => + axios + .get(`${prefixes.http}${relay}`, config) .catch(() => undefined) - }) + ) }) let responses = await Promise.all(requests)