Puppeteer Server
๐ฆฉ 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
โ๏ธ