Giter Site home page Giter Site logo

puppeteer-server's Introduction

Puppeteer Server

FOSSA Status

๐Ÿฆฉ Koa + TypeScript + Rollup + Puppeteer

Prerequisites

Please make sure that Node.js (>= 10.18.1) is installed on your operating system.

Feature

๐ŸŒŒ Separation business logic and Controllers.

๐Ÿฃ Probably the best practice for Puppeteer project.

๐Ÿงฉ Configured routing.

๐Ÿšง Eslint configuration.

โšก Fast build with Rollup.

๐Ÿ•Š Extensible PDF watermark, header and footer.

๐Ÿงฒ Supports merging of multiple PDF files.

๐Ÿ”ฅ HMR.

Project structure

โ”œโ”€โ”€ src
โ”‚   โ”œโ”€โ”€ controllers/ ---  Server controllers
โ”‚   โ”œโ”€โ”€ services/    ---  Server services
โ”‚   โ”œโ”€โ”€ config.ts    ---  About Environments variable
โ”‚   โ”œโ”€โ”€ main.ts      ---  Entry file
โ”‚   โ””โ”€โ”€ routes.ts    ---  Configs for routing controllers

Installation

pnpm install

Running Development

pnpm dev

Running Production

The project has built-in a pm2, running the pnpm start will automatically manage the process by pm2.

Run pnpm build to build, then run pnpm start to start the process managed by pm2:

pnpm start

API

  • GET /image

Generate screenshot.

curl --location --request GET \
'http://localhost:5000/image?url=https://www.baidu.com' \
--output test-image.png
  • GET /simple-pdf

Generate pdf.

curl --location --request GET \
'http://localhost:5000/simple-pdf?url=https://www.google.com/' \
--output test-simple-pdf.pdf
  • POST /pdf

Generate pdf with elements such as headers and footers.

curl --location --request POST 'http://localhost:5000/pdf' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'url=http://www.google.com' \
--data-urlencode 'cookies[0].name=token' \
--data-urlencode 'cookies[0].value=9s2d4c16-f072-16eg-b134-0642ap190006' \
--data-urlencode 'cookies[0].domain=www.google.com' --output test-complex-pdf.pdf
  • POST /combine-pdf

Merge multiple PDF files into one file.

See Merge Test

Routing

In order to make the routing information more readable and transparent, the form of configuration is adopted here.

You can create an array and then write the routing meta information into the array, and reuse it in the src/routes.ts

const routes: Array<RouteConfig> = [
  {
    path: '/',
    method: 'get',
    action: homeController.hello
  },
  // here...
]

License

โœŒ๏ธ

MIT

FOSSA Status

puppeteer-server's People

Contributors

fossabot avatar pdsuwwz avatar renovate-bot avatar

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.