Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
FIX: prevent random ENOTFOUND errors by explicitly using ipv4
Browse files Browse the repository at this point in the history
Apparently it can happen that requests within node will randomly switch between ipv6 and ipv4 unless one of them is explicitly specified. I have configured ipv4 for now and that seems to fix it.

See also:

* axios/axios#444
* nodejs/node#5436
  • Loading branch information
martinhauke committed Oct 19, 2022
1 parent 781db27 commit 8fd8ea3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import axios, { AxiosResponse } from 'axios'
import parse, { HTMLElement } from 'node-html-parser'
import { writeResultToConsole } from './Output'
import { URL } from 'url'
import * as https from "https";
import * as http from "http";

type CrawledUrl = {
url: string
Expand All @@ -20,9 +22,13 @@ export type ExternalResource = {
}

const createAxiosPromiseFromUrl = (url: string): Promise<AxiosResponse> => {
const httpAgent = new http.Agent({family: 4})
const httpsAgent = new https.Agent({family: 4})
return axios
.get(url, {
validateStatus: () => true,
httpAgent,
httpsAgent,
})
.catch((e): AxiosResponse => {
return {
Expand Down

0 comments on commit 8fd8ea3

Please sign in to comment.