Fix SSR puppeteer page initialization
This commit is contained in:
		
							parent
							
								
									126e87a746
								
							
						
					
					
						commit
						7f2a459575
					
				| @ -11,7 +11,7 @@ const BROWSER_TIMEOUT = 8000; | |||||||
| const maxAgeMs = (config.PUPPETEER.MAX_PAGE_AGE || (24 * 60 * 60)) * 1000; | const maxAgeMs = (config.PUPPETEER.MAX_PAGE_AGE || (24 * 60 * 60)) * 1000; | ||||||
| const maxConcurrency = config.PUPPETEER.CLUSTER_SIZE; | const maxConcurrency = config.PUPPETEER.CLUSTER_SIZE; | ||||||
| 
 | 
 | ||||||
| interface RepairablePage extends puppeteer.Page { | export interface RepairablePage extends puppeteer.Page { | ||||||
|   repairRequested?: boolean; |   repairRequested?: boolean; | ||||||
|   language?: string | null; |   language?: string | null; | ||||||
|   createdAt?: number; |   createdAt?: number; | ||||||
|  | |||||||
| @ -2,19 +2,11 @@ import * as puppeteer from 'puppeteer'; | |||||||
| import { timeoutExecute } from 'puppeteer-cluster/dist/util'; | import { timeoutExecute } from 'puppeteer-cluster/dist/util'; | ||||||
| import logger from '../logger'; | import logger from '../logger'; | ||||||
| import config from '../config'; | import config from '../config'; | ||||||
| import ReusablePage from './ReusablePage'; | import ReusablePage, { RepairablePage } from './ReusablePage'; | ||||||
| const mempoolHost = config.MEMPOOL.HTTP_HOST + (config.MEMPOOL.HTTP_PORT ? ':' + config.MEMPOOL.HTTP_PORT : ''); | const mempoolHost = config.MEMPOOL.HTTP_HOST + (config.MEMPOOL.HTTP_PORT ? ':' + config.MEMPOOL.HTTP_PORT : ''); | ||||||
| 
 | 
 | ||||||
| const mockImageBuffer = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=", 'base64'); | const mockImageBuffer = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=", 'base64'); | ||||||
| 
 | 
 | ||||||
| interface RepairablePage extends puppeteer.Page { |  | ||||||
|   repairRequested?: boolean; |  | ||||||
|   language?: string | null; |  | ||||||
|   createdAt?: number; |  | ||||||
|   free?: boolean; |  | ||||||
|   index?: number; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| export default class ReusableSSRPage extends ReusablePage { | export default class ReusableSSRPage extends ReusablePage { | ||||||
| 
 | 
 | ||||||
|   public constructor(options: puppeteer.LaunchOptions, puppeteer: any) { |   public constructor(options: puppeteer.LaunchOptions, puppeteer: any) { | ||||||
| @ -33,7 +25,7 @@ export default class ReusableSSRPage extends ReusablePage { | |||||||
| 
 | 
 | ||||||
|     page.on('pageerror', (err) => { |     page.on('pageerror', (err) => { | ||||||
|       console.log(err); |       console.log(err); | ||||||
|       // page.repairRequested = true;
 |       page.repairRequested = true; | ||||||
|     }); |     }); | ||||||
|     await page.setRequestInterception(true); |     await page.setRequestInterception(true); | ||||||
|     page.on('request', req => { |     page.on('request', req => { | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ import * as https from 'https'; | |||||||
| import config from './config'; | import config from './config'; | ||||||
| import { Cluster } from 'puppeteer-cluster'; | import { Cluster } from 'puppeteer-cluster'; | ||||||
| import ReusablePage from './concurrency/ReusablePage'; | import ReusablePage from './concurrency/ReusablePage'; | ||||||
| import ReusableSSRPage from './concurrency/ReusablePage'; | import ReusableSSRPage from './concurrency/ReusableSSRPage'; | ||||||
| import { parseLanguageUrl } from './language/lang'; | import { parseLanguageUrl } from './language/lang'; | ||||||
| import { matchRoute } from './routes'; | import { matchRoute } from './routes'; | ||||||
| import nodejsPath from 'path'; | import nodejsPath from 'path'; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user