sigit-issue-30 #2
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user