From 17640b5402494c278465423779dd1940d8edcb6a Mon Sep 17 00:00:00 2001 From: DanielLordMA Date: Thu, 21 Nov 2019 19:39:25 +1300 Subject: [PATCH 1/2] implement setExtraHTTPHeaders --- src/core/render-core.js | 6 ++++++ src/http/render-http.js | 1 + src/util/validation.js | 2 ++ 3 files changed, 9 insertions(+) diff --git a/src/core/render-core.js b/src/core/render-core.js index c5f02c40..7975da29 100644 --- a/src/core/render-core.js +++ b/src/core/render-core.js @@ -100,6 +100,12 @@ async function render(_opts = {}) { await client.send('Network.setCookies', { cookies: opts.cookies }); } + if (opts.setExtraHTTPHeaders) { + logger.info('Set setExtraHTTPHeaders ..'); + await page.setExtraHTTPHeaders(opts.setExtraHTTPHeaders); + } + + if (opts.html) { logger.info('Set HTML ..'); await page.setContent(opts.html, opts.goto); diff --git a/src/http/render-http.js b/src/http/render-http.js index 2a5c2c2d..7b133665 100644 --- a/src/http/render-http.js +++ b/src/http/render-http.js @@ -113,6 +113,7 @@ function getOptsFromQuery(query) { }, omitBackground: query['screenshot.omitBackground'], }, + setExtraHTTPHeaders:query['setExtraHTTPHeaders'], }; return opts; } diff --git a/src/util/validation.js b/src/util/validation.js index 3c42074e..5aba4938 100644 --- a/src/util/validation.js +++ b/src/util/validation.js @@ -62,6 +62,7 @@ const sharedQuerySchema = Joi.object({ 'screenshot.clip.width': Joi.number(), 'screenshot.clip.height': Joi.number(), 'screenshot.omitBackground': Joi.boolean(), + 'setExtraHTTPHeaders': Joi.object(), }); const renderQuerySchema = Joi.object({ @@ -126,6 +127,7 @@ const renderBodyObject = Joi.object({ omitBackground: Joi.boolean(), }), failEarly: Joi.string(), + setExtraHTTPHeaders: Joi.object(), }); const renderBodySchema = Joi.alternatives([ From 7f484cf803da77b504b02abe3717b7b17a42bf59 Mon Sep 17 00:00:00 2001 From: DanielLordMA Date: Fri, 29 Nov 2019 16:20:59 +1300 Subject: [PATCH 2/2] Create Dockerfile dockerfile --- dockerfile | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 dockerfile diff --git a/dockerfile b/dockerfile new file mode 100644 index 00000000..1d4e4cc2 --- /dev/null +++ b/dockerfile @@ -0,0 +1,26 @@ +FROM node:8.7.0 + +WORKDIR /usr/src/app +ENV NODE_ENV production +ENV PORT 9000 +EXPOSE 9000 + +RUN apt-get update \ + && apt-get install -yq \ + gconf-service libasound2 libatk1.0-0 libc6 \ + libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 \ + libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 \ + libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 \ + libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \ + libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 \ + libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation \ + libappindicator1 libnss3 lsb-release xdg-utils wget \ + && rm -r /var/lib/apt/lists/* + +COPY package.json . + +RUN npm install + +COPY . . + +CMD ["node", "src/index.js"]