@@ -3,25 +3,25 @@ const axios = require('axios');
33const { JSDOM } = require ( 'jsdom' ) ;
44const imageSize = require ( 'image-size' ) ;
55
6- const axiosInstance = axios . create ( ) ;
7- axiosInstance . defaults . maxRedirects = 0 ; // Set to 0 to prevent automatic redirects
8- axiosInstance . defaults . timeout = 1000 ; // Set to 1 second
9- axiosInstance . defaults . adapter = 'http' ;
10- axiosInstance . defaults . headers [ 'Accept' ] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' ;
11- axiosInstance . defaults . headers [ 'Accept-Encoding' ] = 'gzip, deflate, br' ;
12- axiosInstance . defaults . headers [ 'Accept-Language' ] = 'en-US,en;q=1' ;
13- axiosInstance . defaults . headers [ 'Cache-Control' ] = 'no-cache' ;
6+ const axiosInstance = axios . create ( {
7+ timeout : 8000 ,
8+ maxRedirects : 5 ,
9+ headers : {
10+ 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' ,
11+ 'Accept-Encoding' : 'gzip, deflate, br' ,
12+ 'Accept-Language' : 'en-US,en;q=1' ,
13+ 'Cache-Control' : 'no-cache' ,
14+ 'User-Agent' : 'Mozilla/5.0 (compatible; PasskeysCrawler/1.0)'
15+ }
16+ } ) ;
17+
1418axiosInstance . interceptors . response . use (
15- response => response ,
19+ r => r ,
1620 error => {
17- if ( error . response && [ 301 , 302 ] . includes ( error . response . status ) ) {
18- let redirectUrl = error . response . headers . location ;
19- if ( redirectUrl . startsWith ( '/' ) ) {
20- const { url } = error . response . config ;
21- redirectUrl = url + redirectUrl ;
22- }
23- console . log ( 'Redirecting to' , error . response . headers . location ) ;
24- return axiosInstance . get ( redirectUrl ) ;
21+ const res = error . response ;
22+ if ( res && ( res . status === 301 || res . status === 302 ) ) {
23+ const redirectUrl = new URL ( res . headers . location , res . config . url ) . href ;
24+ return axiosInstance . get ( redirectUrl , { timeout : 8000 } ) ;
2525 }
2626 return Promise . reject ( error ) ;
2727 }
@@ -224,10 +224,14 @@ async function processDomains(inputFile, outputFile, debug = false) {
224224 const results = [ ] ;
225225
226226 for ( const domain of domains ) {
227- const result = await fetchDomainInfo ( domain , debug ) ;
228- console . log ( domain , result ) ;
229- if ( result ) {
230- results . push ( result ) ;
227+ try {
228+ const result = await fetchDomainInfo ( domain , debug ) ;
229+ console . log ( domain , result ) ;
230+ if ( result ) {
231+ results . push ( result ) ;
232+ }
233+ } catch ( error ) {
234+ console . error ( `Error fetching domain ${ domain } :` , error ) ;
231235 }
232236 }
233237
0 commit comments