mirror of
https://github.com/mempool/mempool.git
synced 2025-02-22 14:22:44 +01:00
Merge pull request #2442 from mononaut/unfurler-optional-puppeteer
Option to disable puppeteer in unfurler
This commit is contained in:
commit
e1c98ceaa2
3 changed files with 20 additions and 7 deletions
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Reference in a new issue