diff --git a/package-lock.json b/package-lock.json index 4c76a63..f883342 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "@nostr-dev-kit/ndk": "^0.8.1", "axios": "^1.4.0", - "debug": "^4.3.4", "file-type": "^18.5.0", "form-data": "^4.0.0", "form-data-encoder": "^3.0.0", diff --git a/package.json b/package.json index 0fb21bb..eee9ee8 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "dependencies": { "@nostr-dev-kit/ndk": "^0.8.1", "axios": "^1.4.0", - "debug": "^4.3.4", "file-type": "^18.5.0", "form-data": "^4.0.0", "form-data-encoder": "^3.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 12b8c30..77f8622 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -13,10 +13,7 @@ importers: version: 0.8.1(typescript@5.0.4) axios: specifier: ^1.4.0 - version: 1.4.0(debug@4.3.4) - debug: - specifier: ^4.3.4 - version: 4.3.4 + version: 1.4.0 file-type: specifier: ^18.5.0 version: 18.5.0 @@ -34,7 +31,7 @@ importers: version: 3.0.0 lnbits: specifier: ^1.1.5 - version: 1.1.5(debug@4.3.4) + version: 1.1.5 tslib: specifier: ~2.5 version: 2.5.3 @@ -3598,15 +3595,15 @@ snapshots: dependencies: possible-typed-array-names: 1.0.0 - axios@0.21.4(debug@4.3.4): + axios@0.21.4: dependencies: - follow-redirects: 1.15.2(debug@4.3.4) + follow-redirects: 1.15.2 transitivePeerDependencies: - debug - axios@1.4.0(debug@4.3.4): + axios@1.4.0: dependencies: - follow-redirects: 1.15.2(debug@4.3.4) + follow-redirects: 1.15.2 form-data: 4.0.0 proxy-from-env: 1.1.0 transitivePeerDependencies: @@ -4269,9 +4266,7 @@ snapshots: flatted@3.2.7: {} - follow-redirects@1.15.2(debug@4.3.4): - optionalDependencies: - debug: 4.3.4 + follow-redirects@1.15.2: {} for-each@0.3.3: dependencies: @@ -4942,9 +4937,9 @@ snapshots: lines-and-columns@1.2.4: {} - lnbits@1.1.5(debug@4.3.4): + lnbits@1.1.5: dependencies: - axios: 0.21.4(debug@4.3.4) + axios: 0.21.4 typescript: 4.9.5 transitivePeerDependencies: - debug 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) diff --git a/src/main.ts b/src/main.ts index de1a7da..f05ff69 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,4 @@ import NDK, { NDKEvent } from '@nostr-dev-kit/ndk' -import debug from 'debug' import { onNewSummarizationJob } from './job-types/summarization.js' import { complete, speechToTextJob } from './job-types/speech-to-text.js' import getSigner from './local-signer.js' @@ -14,7 +13,7 @@ import { blockChainBlockNumberJob } from './job-types/blockChain-block-number.js import { relayInfoJob } from './job-types/relay-info.js' import { JobType, JobTypes } from './types/index.js' -export const log = debug('fool-me-once-dvm') +export const log = (obj1: any, obj2?: any) => console.log(obj1, obj2 || '') export const configFile = process.argv[2] || `${process.env.HOME}/.fool-me-once.json`