Giter Site home page Giter Site logo

cogoken / puppeteer-service Goto Github PK

View Code? Open in Web Editor NEW

This project forked from leocode/puppeteer-service

0.0 0.0 0.0 183 KB

Containerized Puppeteer which allows to render images and PDFs of given webpage or HTML code

License: MIT License

JavaScript 3.10% TypeScript 72.16% HTML 0.27% Dockerfile 11.75% Shell 12.72%

puppeteer-service's Introduction

puppeteer-service

Containerized Puppeteer which allows to render images and PDFs of given webpage or HTML code

Quick start - start container, convert HTML to PDF

For production: Remember to select precise version tag for the image (e.g. leocode/puppeteer-service:1.1.0)

docker build -t pup-test leocode/puppeteer-service

docker run -it --rm -p 3000:3000 pup-test

curl -d '{"html":"<strong>Hello world</strong>"}' -H "Content-Type: application/json" -X POST http://localhost:3000/html/pdf > hello-world.pdf

Container installation

Remember to select precise version tag for the image (e.g. leocode/puppeteer-service:1.1.0)

docker run leocode/puppeteer-service

The same can be used for docker-compose:

services:
  puppeteer:
    image: leocode/puppeteer-service

Documentation

Starting container automatically starts API server.

It listens on port 3000.

HTML to PDF

Method: POST

URL: /html/pdf

Body

{
  "html": "<html><head><style></style></head><body>Content</body></html>"
}

Response

HTTP/1.1 200 OK
content-type: application/octet-stream

<binary>

HTML to PNG

Method: POST

URL: /html/png

Body

{
  "html": "<html><head><style></style></head><body>Content</body></html>",
  "viewport": {
    "width": 1024,
    "height": 768
  }
}

Response

HTTP/1.1 200 OK
content-type: application/octet-stream

<binary>

URL to PDF

Method: POST

URL: /url/pdf

Body

{
  "url": "https://www.wikipedia.org/"
}

Response

HTTP/1.1 200 OK
content-type: application/octet-stream

<binary>

URL to PNG

Method: POST

URL: /url/png

Body

{
  "url": "https://www.wikipedia.org/",
  "viewport": {
    "width": 1024,
    "height": 768
  }
}

Response

HTTP/1.1 200 OK
content-type: application/octet-stream

<binary>

Development

Dependencies:

  • Docker
yarn start:dev

Start container with API. Wait until logs from server appear (due to one-line command docker build output is muted). It may take up to few minutes. Consecutive starts (after code change) should be faster.

You can test production build using

yarn start:prod

Versioning

We use semver for versioning. Release should be tagged with vX.Y.Z, so the version is picked up by Docker Hub autobuild.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.