sigit-issue-30 #2

Merged
y merged 2 commits from sigit-issue-30 into master 2024-05-28 06:03:59 +00:00
Showing only changes of commit 7322f7c7f5 - Show all commits

View File

@ -2,6 +2,7 @@ import { NDKEvent } from '@nostr-dev-kit/ndk'
import { log } from '../main.js' import { log } from '../main.js'
import axios from 'axios' import axios from 'axios'
import { RelayInfo } from '../types/index.js' import { RelayInfo } from '../types/index.js'
import https from 'https'
export const relayInfoJob = async (event: NDKEvent): Promise<string> => { export const relayInfoJob = async (event: NDKEvent): Promise<string> => {
log('New relay-info job', event.rawEvent()) log('New relay-info job', event.rawEvent())
@ -22,8 +23,15 @@ export const relayInfoJob = async (event: NDKEvent): Promise<string> => {
} }
const prefixes = { wss: 'wss://', https: 'https://', http: 'http://' } 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) => { const requests = relays.map((relay) => {
@ -32,12 +40,12 @@ export const relayInfoJob = async (event: NDKEvent): Promise<string> => {
} }
return axios return axios
.get<RelayInfo>((relay = `${prefixes.https}${relay}`), headers) .get<RelayInfo>((relay = `${prefixes.https}${relay}`), config)
.catch(() => { .catch(() =>
return axios axios
.get<RelayInfo>(`${prefixes.http}${relay}`, headers) .get<RelayInfo>(`${prefixes.http}${relay}`, config)
.catch(() => undefined) .catch(() => undefined)
}) )
}) })
let responses = await Promise.all(requests) let responses = await Promise.all(requests)