Option to disable puppeteer in unfurler
This commit is contained in:
		
							parent
							
								
									feff3c52ef
								
							
						
					
					
						commit
						c4e656e275
					
				| @ -9,6 +9,7 @@ | |||||||
|     "NETWORK": "bitcoin" // "bitcoin" | "liquid" | "bisq" (optional - defaults to "bitcoin") |     "NETWORK": "bitcoin" // "bitcoin" | "liquid" | "bisq" (optional - defaults to "bitcoin") | ||||||
|   }, |   }, | ||||||
|   "PUPPETEER": { |   "PUPPETEER": { | ||||||
|  |     "DISABLE": false, // optional, boolean, disables puppeteer and /render endpoints | ||||||
|     "CLUSTER_SIZE": 2, |     "CLUSTER_SIZE": 2, | ||||||
|     "EXEC_PATH": "/usr/local/bin/chrome", // optional |     "EXEC_PATH": "/usr/local/bin/chrome", // optional | ||||||
|     "MAX_PAGE_AGE": 86400, // maximum lifetime of a page session (in seconds) |     "MAX_PAGE_AGE": 86400, // maximum lifetime of a page session (in seconds) | ||||||
|  | |||||||
| @ -11,6 +11,7 @@ interface IConfig { | |||||||
|     NETWORK?: string; |     NETWORK?: string; | ||||||
|   }; |   }; | ||||||
|   PUPPETEER: { |   PUPPETEER: { | ||||||
|  |     DISABLE: boolean; | ||||||
|     CLUSTER_SIZE: number; |     CLUSTER_SIZE: number; | ||||||
|     EXEC_PATH?: string; |     EXEC_PATH?: string; | ||||||
|     MAX_PAGE_AGE?: number; |     MAX_PAGE_AGE?: number; | ||||||
| @ -28,6 +29,7 @@ const defaults: IConfig = { | |||||||
|     'HTTP_PORT': 4200, |     'HTTP_PORT': 4200, | ||||||
|   }, |   }, | ||||||
|   'PUPPETEER': { |   'PUPPETEER': { | ||||||
|  |     'DISABLE': false, | ||||||
|     'CLUSTER_SIZE': 1, |     'CLUSTER_SIZE': 1, | ||||||
|   }, |   }, | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -37,12 +37,14 @@ class Server { | |||||||
|       .use(express.text()) |       .use(express.text()) | ||||||
|       ; |       ; | ||||||
| 
 | 
 | ||||||
|  |     if (!config.PUPPETEER.DISABLE) { | ||||||
|       this.cluster = await Cluster.launch({ |       this.cluster = await Cluster.launch({ | ||||||
|           concurrency: ReusablePage, |           concurrency: ReusablePage, | ||||||
|           maxConcurrency: config.PUPPETEER.CLUSTER_SIZE, |           maxConcurrency: config.PUPPETEER.CLUSTER_SIZE, | ||||||
|           puppeteerOptions: puppeteerConfig, |           puppeteerOptions: puppeteerConfig, | ||||||
|       }); |       }); | ||||||
|       await this.cluster?.task(async (args) => { return this.clusterTask(args) }); |       await this.cluster?.task(async (args) => { return this.clusterTask(args) }); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     this.setUpRoutes(); |     this.setUpRoutes(); | ||||||
| 
 | 
 | ||||||
| @ -64,7 +66,11 @@ class Server { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   setUpRoutes() { |   setUpRoutes() { | ||||||
|  |     if (!config.PUPPETEER.DISABLE) { | ||||||
|       this.app.get('/render*', async (req, res) => { return this.renderPreview(req, res) }) |       this.app.get('/render*', async (req, res) => { return this.renderPreview(req, res) }) | ||||||
|  |     } else { | ||||||
|  |       this.app.get('/render*', async (req, res) => { return this.renderDisabled(req, res) }) | ||||||
|  |     } | ||||||
|     this.app.get('*', (req, res) => { return this.renderHTML(req, res) }) |     this.app.get('*', (req, res) => { return this.renderHTML(req, res) }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -111,6 +117,10 @@ class Server { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   async renderDisabled(req, res) { | ||||||
|  |     res.status(500).send("preview rendering disabled"); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   async renderPreview(req, res) { |   async renderPreview(req, res) { | ||||||
|     try { |     try { | ||||||
|       const path = req.params[0] |       const path = req.params[0] | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user