puppeter not longer launch instances at service boot
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
38965ba50e
commit
071d15b79d
|
@ -1,11 +1,9 @@
|
|||
const express = require('express');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const puppeteer = require('puppeteer');
|
||||
|
||||
const templatesPath = path.resolve(__dirname, './templates');
|
||||
const componentsPath = path.resolve(__dirname, './core/components');
|
||||
const config = require('./core/config');
|
||||
|
||||
module.exports = async app => {
|
||||
global.appPath = __dirname;
|
||||
|
@ -55,21 +53,4 @@ module.exports = async app => {
|
|||
app.use(`/api/${templateName}/assets`, express.static(assetsDir));
|
||||
});
|
||||
});
|
||||
|
||||
// Instantiate Puppeteer browser
|
||||
async function launchBrowser() {
|
||||
config.browser = await puppeteer.launch({
|
||||
headless: true,
|
||||
args: [
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox',
|
||||
'--single-process',
|
||||
'--no-zygote'
|
||||
]
|
||||
});
|
||||
|
||||
config.browser.on('disconnected', launchBrowser);
|
||||
}
|
||||
|
||||
launchBrowser();
|
||||
};
|
||||
|
|
|
@ -2,6 +2,7 @@ const fs = require('fs');
|
|||
const path = require('path');
|
||||
const config = require('./config');
|
||||
const Component = require('./component');
|
||||
const puppeteer = require('puppeteer');
|
||||
|
||||
if (!process.env.OPENSSL_CONF)
|
||||
process.env.OPENSSL_CONF = '/etc/ssl/';
|
||||
|
@ -31,7 +32,19 @@ class Report extends Component {
|
|||
if (fs.existsSync(fullPath))
|
||||
options = require(optionsPath);
|
||||
|
||||
const page = (await config.browser.pages())[0];
|
||||
const browser = await puppeteer.launch({
|
||||
headless: true,
|
||||
args: [
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox',
|
||||
'--single-process',
|
||||
'--no-zygote'
|
||||
]
|
||||
});
|
||||
|
||||
// browser.on('disconnected', launchBrowser);
|
||||
|
||||
const page = (await browser.pages())[0];
|
||||
await page.emulateMedia('screen');
|
||||
await page.setContent(template);
|
||||
|
||||
|
@ -51,6 +64,8 @@ class Report extends Component {
|
|||
|
||||
const buffer = await page.pdf(options);
|
||||
|
||||
await browser.close();
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue