From c337122ccba3ee2ad40521bd7f5fa90707e893b2 Mon Sep 17 00:00:00 2001 From: Sebastian Schubotz Date: Sat, 24 Apr 2021 15:22:17 +0200 Subject: [PATCH] Add option to ignore certificate errors #9 --- README.md | 1 + config.js | 2 ++ index.js | 19 ++++++++++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e81efd2..4f3f55e 100644 --- a/README.md +++ b/README.md @@ -49,3 +49,4 @@ Some advanced variables for local usage which shouldn't be necessary when using - `OUTPUT_PATH=./output.png` (destination of rendered image. `OUTPUT_2`, `OUTPUT_3`, ... is also supported) - `PORT=5000` (port of server, which returns the last image) - `USE_IMAGE_MAGICK=false` (use ImageMagick instead of GraphicsMagick) +- `UNSAFE_IGNORE_CERTIFICATE_ERRORS=true` (ignore certificate errors of e.g. self-signed certificates at your own risk) diff --git a/config.js b/config.js index a3b588a..322d8cc 100644 --- a/config.js +++ b/config.js @@ -42,4 +42,6 @@ module.exports = { renderingTimeout: process.env.RENDERING_TIMEOUT || 10000, language: process.env.LANGUAGE || "en", debug: process.env.DEBUG === "true", + ignoreCertificateErrors: + process.env.UNSAFE_IGNORE_CERTIFICATE_ERRORS === "true", }; diff --git a/index.js b/index.js index 574f99d..55e7140 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,8 @@ const gm = require("gm"); "--disable-dev-shm-usage", "--no-sandbox", `--lang=${config.language}`, - ], + config.ignoreCertificateErrors && "--ignore-certificate-errors", + ].filter((x) => x), headless: config.debug !== true, }); @@ -76,9 +77,9 @@ const gm = require("gm"); pageNumber.length > config.pages.length || pageNumber < 1 ) { - console.error('Invalid page requested: ' + pageNumber); + console.error("Invalid page requested: " + pageNumber); response.writeHead(400); - response.end('Invalid page'); + response.end("Invalid page"); return; } try { @@ -113,7 +114,11 @@ async function renderAndConvertAsync(browser) { await renderUrlToImageAsync(browser, pageConfig, url, tempPath); console.log(`Converting rendered screenshot of ${url} to grayscale png...`); - await convertImageToKindleCompatiblePngAsync(pageConfig, tempPath, outputPath); + await convertImageToKindleCompatiblePngAsync( + pageConfig, + tempPath, + outputPath + ); fs.unlink(tempPath); console.log(`Finished ${url}`); @@ -181,7 +186,11 @@ async function renderUrlToImageAsync(browser, pageConfig, url, path) { } } -function convertImageToKindleCompatiblePngAsync(pageConfig, inputPath, outputPath) { +function convertImageToKindleCompatiblePngAsync( + pageConfig, + inputPath, + outputPath +) { return new Promise((resolve, reject) => { gm(inputPath) .options({