Merge pull request #2442 from mononaut/unfurler-optional-puppeteer

Option to disable puppeteer in unfurler
This commit is contained in:
wiz 2022-08-30 13:21:12 +02:00 committed by GitHub
commit e1c98ceaa2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 7 deletions

View file

@ -9,6 +9,7 @@
"NETWORK": "bitcoin" // "bitcoin" | "liquid" | "bisq" (optional - defaults to "bitcoin")
},
"PUPPETEER": {
"DISABLE": false, // optional, boolean, disables puppeteer and /render endpoints
"CLUSTER_SIZE": 2,
"EXEC_PATH": "/usr/local/bin/chrome", // optional
"MAX_PAGE_AGE": 86400, // maximum lifetime of a page session (in seconds)

View file

@ -11,6 +11,7 @@ interface IConfig {
NETWORK?: string;
};
PUPPETEER: {
DISABLE: boolean;
CLUSTER_SIZE: number;
EXEC_PATH?: string;
MAX_PAGE_AGE?: number;
@ -28,6 +29,7 @@ const defaults: IConfig = {
'HTTP_PORT': 4200,
},
'PUPPETEER': {
'DISABLE': false,
'CLUSTER_SIZE': 1,
},
};

View file

@ -37,12 +37,14 @@ class Server {
.use(express.text())
;
this.cluster = await Cluster.launch({
concurrency: ReusablePage,
maxConcurrency: config.PUPPETEER.CLUSTER_SIZE,
puppeteerOptions: puppeteerConfig,
});
await this.cluster?.task(async (args) => { return this.clusterTask(args) });
if (!config.PUPPETEER.DISABLE) {
this.cluster = await Cluster.launch({
concurrency: ReusablePage,
maxConcurrency: config.PUPPETEER.CLUSTER_SIZE,
puppeteerOptions: puppeteerConfig,
});
await this.cluster?.task(async (args) => { return this.clusterTask(args) });
}
this.setUpRoutes();
@ -64,7 +66,11 @@ class Server {
}
setUpRoutes() {
this.app.get('/render*', async (req, res) => { return this.renderPreview(req, res) })
if (!config.PUPPETEER.DISABLE) {
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) })
}
@ -111,6 +117,10 @@ class Server {
}
}
async renderDisabled(req, res) {
res.status(500).send("preview rendering disabled");
}
async renderPreview(req, res) {
try {
const path = req.params[0]