Skip to content

hartl3y94/puppeteer-server

Β 
Β 

Repository files navigation

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

About

🦩 Koa + TS + Rollup + Puppeteer

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 98.6%
  • Shell 1.4%