alvarcarto / url-to-pdf-api

Web page PDF/PNG rendering done right. Self-hosted service for rendering receipts, invoices, or any content.
MIT License
7.03k stars 779 forks source link

Only HTTPS allowed? #8

Closed thebetterjort closed 7 years ago

thebetterjort commented 7 years ago

http://localhost:9000/api/render?url=http://google.com


2017-10-05T16:05:58.491Z - warn: [error-logger.js] Request headers: host=localhost:9000, user-agent=Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0, accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, accept-language=en-US,en;q=0.5, accept-encoding=gzip, deflate, connection=keep-alive, upgrade-insecure-requests=1
2017-10-05T16:05:58.491Z - warn: [error-logger.js] Request parameters:
2017-10-05T16:05:58.491Z - warn: [error-logger.js] Request body:
2017-10-05T16:05:58.491Z - warn: [error-logger.js] Error: Only HTTPS allowed.
GET /api/render?url=https://google.com 403 0.824 ms - 74
thebetterjort commented 7 years ago

When connecting to https://localhost:9000 I get this from firefox.

Secure Connection Failed

The connection to localhost:9000 was interrupted while the page was loading.

    The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.
    Please contact the website owners to inform them of this problem.

I have a self-signed cert for my corporation. How can I disable such checks?

kimmobrunfeldt commented 7 years ago

By default, this service refuses to work without https. In local development, you need to have ALLOW_HTTP=true environment variable set when launching the server. By following install instructions here: https://github.com/alvarcarto/url-to-pdf-api#2-local-development the environment variable should appear to your local shell via the .env file.

You can also force the env variable in the command: ALLOW_HTTP=true npm start

thebetterjort commented 7 years ago

Trying to dockeritize this project. The env aren't being honored. Any ideas?

FROM node:alpine

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/
RUN npm set strict-ssl false
RUN npm install

# Bundle app source
COPY . /usr/src/app

RUN source .env

EXPOSE 9000

CMD ["npm", "run", "start"]

.env

export NODE_ENV=development
export PORT=9000
export ALLOW_HTTP=true

I resolved this by passing ALLOW_HTTP=true in package.json

thebetterjort commented 7 years ago
17-10-05T16:40:38.809Z - info: [app.js] ALLOW_HTTP=true, unsafe requests are allowed. Don't use this in production.
2017-10-05T16:40:38.810Z - info: [app.js] Using CORS options: origin=undefined, methods=[GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH]
2017-10-05T16:40:38.811Z - warn: [router.js] Warning: no authentication required to use the API
2017-10-05T16:40:38.816Z - info: [index.js] Express server listening on http://localhost:9000/ in development mode
2017-10-05T16:41:07.976Z - info: [pdf-core.js] Rendering with opts: {
  "scrollPage": false,
  "emulateScreenMedia": true,
  "viewport": {
    "width": 1600,
    "height": 1200
  },
  "goto": {
    "waitUntil": "networkidle",
    "networkIdleTimeout": 2000
  },
  "pdf": {
    "format": "A4",
    "printBackground": true
  },
  "url": "http://google.com"
}
events.js:182
      throw er; // Unhandled 'error' event
      ^

Error: spawn /usr/src/app/node_modules/puppeteer/.local-chromium/linux-499413/chrome-linux/chrome ENOENT
    at _errnoException (util.js:1019:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
    at onErrorNT (internal/child_process.js:374:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
[nodemon] app crashed - waiting for file changes before starting...
thebetterjort commented 7 years ago

https://github.com/GoogleChrome/puppeteer/issues/379

Seems to be related to Docker and Chromium and not your package. Many thanks for your work.

SimonKlausLudwig commented 4 years ago

docker run -e ALLOW_HTTP=true -p 9000:9000 anthonylau/url-to-pdf-api