From 0116830ed57b837dbc17edf1a7ed3f06ae1ebf16 Mon Sep 17 00:00:00 2001 From: Bobby Date: Tue, 28 Jun 2022 01:40:19 +0530 Subject: Configuring Dockerfile to run Headless Chromium --- Dockerfile | 12 ++++++++++++ routes/api/screenshot.js | 4 +++- site.config.yml | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..2467eb6b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM zenika/alpine-chrome:89-with-node-14 + +COPY package*.json ./ + +RUN npm install + +COPY . . + +ENV PUPPETEER_EXECUTABLE_PATH='/usr/bin/chromium-browser' + +EXPOSE 8080 +CMD [ "node", "server.js" ] diff --git a/routes/api/screenshot.js b/routes/api/screenshot.js index f1ed3297..f55ffc10 100644 --- a/routes/api/screenshot.js +++ b/routes/api/screenshot.js @@ -1,13 +1,15 @@ const router = require("express").Router(); const puppeteer = require("puppeteer"); const fs = require("fs"); +const yaml = require("yaml"); +const config = yaml.parse(fs.readFileSync("site.config.yml", "utf8")); router.get("/", async (req, res) => { const browser = await puppeteer.launch(); const page = await browser.newPage(); page.setViewport({ width: 1920, height: 1080 }); // Go to the url - await page.goto("https://www.thatcomputerscientist.com/", { + await page.goto(config.url, { waitUntil: "networkidle2", }); // Take a screenshot diff --git a/site.config.yml b/site.config.yml index bf23097e..6992e660 100644 --- a/site.config.yml +++ b/site.config.yml @@ -1,2 +1,4 @@ # This file contains all the global configuration for the website domain: 'thatcomputerscientist.com' +url: 'https://www.thatcomputerscientist.com' +title: 'That Computer Scientist' \ No newline at end of file -- cgit v1.2.3