Skip to content

Commit

Permalink
Add option to ignore certificate errors #9
Browse files Browse the repository at this point in the history
  • Loading branch information
sibbl committed Apr 24, 2021
1 parent 9d8c6cc commit c337122
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
19 changes: 14 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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}`);
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit c337122

Please sign in to comment.