diff --git a/unfurler/config.sample.json b/unfurler/config.sample.json index 64f56c1f7..0e4e8d530 100644 --- a/unfurler/config.sample.json +++ b/unfurler/config.sample.json @@ -9,8 +9,8 @@ "NETWORK": "bitcoin" // "bitcoin" | "liquid" | "bisq" (optional - defaults to "bitcoin") }, "PUPPETEER": { - "DISABLE": false, // optional, boolean, disables puppeteer and /render endpoints - "CLUSTER_SIZE": 2, + "ENABLED": false, // optional, boolean, enables puppeteer and /render endpoints (default true) + "CLUSTER_SIZE": 2, // maximum number of parallel chromium pages. CLUSTER_SIZE=0 implies ENABLED=false "EXEC_PATH": "/usr/local/bin/chrome", // optional "MAX_PAGE_AGE": 86400, // maximum lifetime of a page session (in seconds) "RENDER_TIMEOUT": 3000, // timeout for preview image rendering (in ms) (optional) diff --git a/unfurler/src/config.ts b/unfurler/src/config.ts index 3c4a4e422..c04f58007 100644 --- a/unfurler/src/config.ts +++ b/unfurler/src/config.ts @@ -11,7 +11,7 @@ interface IConfig { NETWORK?: string; }; PUPPETEER: { - DISABLE: boolean; + ENABLED: boolean; CLUSTER_SIZE: number; EXEC_PATH?: string; MAX_PAGE_AGE?: number; @@ -29,7 +29,7 @@ const defaults: IConfig = { 'HTTP_PORT': 4200, }, 'PUPPETEER': { - 'DISABLE': false, + 'ENABLED': true, 'CLUSTER_SIZE': 1, }, }; diff --git a/unfurler/src/index.ts b/unfurler/src/index.ts index 167225af5..305a0a4c2 100644 --- a/unfurler/src/index.ts +++ b/unfurler/src/index.ts @@ -13,6 +13,8 @@ if (config.PUPPETEER.EXEC_PATH) { puppeteerConfig.executablePath = config.PUPPETEER.EXEC_PATH; } +const puppeteerEnabled = config.PUPPETEER.ENABLED && (config.PUPPETEER.CLUSTER_SIZE > 0); + class Server { private server: http.Server | undefined; private app: Application; @@ -24,7 +26,7 @@ class Server { constructor() { this.app = express(); this.mempoolHost = config.MEMPOOL.HTTP_HOST + (config.MEMPOOL.HTTP_PORT ? ':' + config.MEMPOOL.HTTP_PORT : ''); - this.secureHost = this.mempoolHost.startsWith('https'); + this.secureHost = config.SERVER.HOST.startsWith('https'); this.network = config.MEMPOOL.NETWORK || 'bitcoin'; this.startServer(); } @@ -39,7 +41,7 @@ class Server { .use(express.text()) ; - if (!config.PUPPETEER.DISABLE) { + if (puppeteerEnabled) { this.cluster = await Cluster.launch({ concurrency: ReusablePage, maxConcurrency: config.PUPPETEER.CLUSTER_SIZE, @@ -68,7 +70,7 @@ class Server { } setUpRoutes() { - if (!config.PUPPETEER.DISABLE) { + if (puppeteerEnabled) { 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) })