fix: Puppeteer nutzt System-Chromium direkt, kein @sparticuz
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
"puppeteer-core": "^22.0.0",
|
"puppeteer-core": "^22.0.0"
|
||||||
"@sparticuz/chromium": "^123.0.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,17 +174,39 @@ router.post('/pdf', authenticate, async (req, res) => {
|
|||||||
const tmpFile = path.join('/tmp', `pwk_${crypto.randomBytes(8).toString('hex')}.pdf`);
|
const tmpFile = path.join('/tmp', `pwk_${crypto.randomBytes(8).toString('hex')}.pdf`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let puppeteer, chromium;
|
let puppeteer;
|
||||||
try { puppeteer = require('puppeteer-core'); chromium = require('@sparticuz/chromium'); }
|
try { puppeteer = require('puppeteer-core'); }
|
||||||
catch { try { puppeteer = require('puppeteer'); chromium = null; }
|
catch { try { puppeteer = require('puppeteer'); }
|
||||||
catch { return res.status(500).json({ error: 'PDF-Rendering nicht verfügbar' }); } }
|
catch { return res.status(500).json({ error: 'PDF-Rendering nicht verfügbar' }); } }
|
||||||
|
|
||||||
const launchOptions = chromium
|
// System-Chromium aus Alpine nutzen (via CHROMIUM_PATH env oder bekannte Pfade)
|
||||||
? { args: [...chromium.args, '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
|
const executablePath = process.env.CHROMIUM_PATH
|
||||||
defaultViewport: { width: 1280, height: 900 },
|
|| (() => {
|
||||||
executablePath: process.env.CHROMIUM_PATH || await chromium.executablePath(),
|
const candidates = [
|
||||||
headless: true }
|
'/usr/bin/chromium-browser',
|
||||||
: { headless: 'new', args: ['--no-sandbox', '--disable-setuid-sandbox'] };
|
'/usr/bin/chromium',
|
||||||
|
'/usr/bin/google-chrome',
|
||||||
|
'/usr/bin/google-chrome-stable',
|
||||||
|
];
|
||||||
|
const fs2 = require('fs');
|
||||||
|
return candidates.find(p => { try { fs2.accessSync(p); return true; } catch { return false; } })
|
||||||
|
|| '/usr/bin/chromium-browser';
|
||||||
|
})();
|
||||||
|
|
||||||
|
const launchOptions = {
|
||||||
|
executablePath,
|
||||||
|
headless: true,
|
||||||
|
args: [
|
||||||
|
'--no-sandbox',
|
||||||
|
'--disable-setuid-sandbox',
|
||||||
|
'--disable-dev-shm-usage',
|
||||||
|
'--disable-gpu',
|
||||||
|
'--disable-software-rasterizer',
|
||||||
|
'--single-process',
|
||||||
|
'--no-zygote',
|
||||||
|
],
|
||||||
|
defaultViewport: { width: 1280, height: 900 },
|
||||||
|
};
|
||||||
|
|
||||||
browser = await puppeteer.launch(launchOptions);
|
browser = await puppeteer.launch(launchOptions);
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
|
|||||||
Reference in New Issue
Block a user