Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pdsuwwz/puppeteer-server
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.1.0
Choose a base ref
...
head repository: pdsuwwz/puppeteer-server
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Aug 4, 2021

  1. update README

    pdsuwwz committed Aug 4, 2021
    Copy the full SHA
    3c73bd0 View commit details
  2. 📖 update README.md

    pdsuwwz committed Aug 4, 2021
    Copy the full SHA
    839aa0d View commit details
  3. Copy the full SHA
    5a68472 View commit details
  4. Merge pull request #12 from pdsuwwz/feature/typo-for-files

    feat: update sample to simple
    pdsuwwz authored Aug 4, 2021
    Copy the full SHA
    7955c98 View commit details

Commits on Aug 5, 2021

  1. Copy the full SHA
    5211547 View commit details
  2. feat: update main.ts

    pdsuwwz committed Aug 5, 2021
    Copy the full SHA
    60048e9 View commit details
  3. Merge pull request #13 from pdsuwwz/feature/support-attachment-image

    feat: support attachement image
    pdsuwwz authored Aug 5, 2021
    Copy the full SHA
    ebf6f21 View commit details

Commits on Aug 7, 2021

  1. feat: add CORS policy

    pdsuwwz committed Aug 7, 2021
    Copy the full SHA
    0ecf841 View commit details
  2. Merge pull request #14 from pdsuwwz/feature/cors-policy

    feat: add CORS policy
    pdsuwwz authored Aug 7, 2021
    Copy the full SHA
    5b9641f View commit details

Commits on Aug 8, 2021

  1. Copy the full SHA
    2aa828a View commit details
  2. Merge pull request #15 from pdsuwwz/feature/pdf-margin

    feat: add margin control of pdf
    pdsuwwz authored Aug 8, 2021
    Copy the full SHA
    64f29cf View commit details
  3. feat: extract params of pdf

    pdsuwwz committed Aug 8, 2021
    Copy the full SHA
    a6fe0ef View commit details
  4. Merge pull request #16 from pdsuwwz/feature/extract-params-pdf

    feat: extract params of pdf
    pdsuwwz authored Aug 8, 2021
    Copy the full SHA
    05438ae View commit details
  5. feat: combine pdf

    pdsuwwz committed Aug 8, 2021
    Copy the full SHA
    1983494 View commit details

Commits on Aug 9, 2021

  1. Copy the full SHA
    896a2db View commit details
  2. feat: add __test__

    pdsuwwz committed Aug 9, 2021
    Copy the full SHA
    7e7394e View commit details
  3. Merge pull request #17 from pdsuwwz/feature/combine-pdf

    feat: combine pdf
    pdsuwwz authored Aug 9, 2021
    Copy the full SHA
    443aa8e View commit details
  4. Copy the full SHA
    db1cfc4 View commit details
  5. Merge pull request #18 from pdsuwwz/feature/sync-remote

    feat: add sync.sh & update __test__
    pdsuwwz authored Aug 9, 2021
    Copy the full SHA
    c077897 View commit details
  6. update version

    pdsuwwz committed Aug 9, 2021
    Copy the full SHA
    1b3b8e8 View commit details

Commits on Aug 10, 2021

  1. fix: pdfList default value

    pdsuwwz committed Aug 10, 2021
    Copy the full SHA
    346c27a View commit details
  2. feat: add full watermark

    pdsuwwz committed Aug 10, 2021
    Copy the full SHA
    b226224 View commit details

Commits on Aug 11, 2021

  1. Copy the full SHA
    01690ee View commit details

Commits on Aug 12, 2021

  1. feat: support landscape A4

    pdsuwwz committed Aug 12, 2021
    Copy the full SHA
    3e0d85a View commit details
  2. feat: fix typo tab

    pdsuwwz committed Aug 12, 2021
    Copy the full SHA
    6fa3a11 View commit details
  3. Merge pull request #19 from pdsuwwz/feature/landscape-support

    feat: support landscape A4
    pdsuwwz authored Aug 12, 2021
    Copy the full SHA
    ed487eb View commit details

Commits on Aug 16, 2021

  1. Copy the full SHA
    cc519d8 View commit details

Commits on Aug 17, 2021

  1. feat: update .gitattributes

    pdsuwwz committed Aug 17, 2021
    Copy the full SHA
    53d5ee2 View commit details

Commits on Aug 23, 2021

  1. Copy the full SHA
    e1352c0 View commit details

Commits on Aug 27, 2021

  1. feat: Update README.md

    pdsuwwz committed Aug 27, 2021
    Copy the full SHA
    8d9c317 View commit details
  2. feat: Update README.md

    pdsuwwz committed Aug 27, 2021
    Copy the full SHA
    5e98646 View commit details

Commits on Sep 1, 2021

  1. remove ignore for static

    pdsuwwz committed Sep 1, 2021
    Copy the full SHA
    2abe8a0 View commit details

Commits on Sep 15, 2021

  1. Copy the full SHA
    5d62315 View commit details
  2. Copy the full SHA
    9efa8f0 View commit details

Commits on Dec 16, 2021

  1. update README

    pdsuwwz committed Dec 16, 2021
    Copy the full SHA
    7dbfdc3 View commit details
  2. 🤔 update README

    pdsuwwz committed Dec 16, 2021
    Copy the full SHA
    ee3241f View commit details

Commits on Dec 21, 2021

  1. Add license scan report and status

    Signed off by: fossabot <badges@fossa.com>
    fossabot committed Dec 21, 2021
    Copy the full SHA
    7c26028 View commit details
  2. Copy the full SHA
    a1f4937 View commit details
  3. Merge pull request #20 from fossabot/add-license-scan-badge

    Add license scan report and status
    pdsuwwz authored Dec 21, 2021
    Copy the full SHA
    654ad74 View commit details
  4. Copy the full SHA
    f240a90 View commit details
  5. Merge pull request #21 from pdsuwwz/feature/upgrade2pnpm

    📦 feat: upgrade from yarn to pnpm
    pdsuwwz authored Dec 21, 2021
    Copy the full SHA
    7026787 View commit details
  6. update README

    pdsuwwz committed Dec 21, 2021
    Copy the full SHA
    9abd1c9 View commit details
  7. update pkg version

    pdsuwwz committed Dec 21, 2021
    Copy the full SHA
    0d7e5cd View commit details
  8. Copy the full SHA
    5e3eeaa View commit details

Commits on Dec 26, 2021

  1. Add renovate.json

    renovate-bot committed Dec 26, 2021
    Copy the full SHA
    db9ea68 View commit details
  2. Update renovate.json

    pdsuwwz authored Dec 26, 2021
    Copy the full SHA
    0f56a19 View commit details
  3. Merge pull request #22 from pdsuwwz/renovate/configure

    Configure Renovate
    pdsuwwz authored Dec 26, 2021
    Copy the full SHA
    f3fb8bb View commit details
  4. Update renovate.json

    pdsuwwz authored Dec 26, 2021
    Copy the full SHA
    3ef7c11 View commit details
  5. Copy the full SHA
    b519f17 View commit details
  6. 🍍 feat: lint

    pdsuwwz committed Dec 26, 2021
    Copy the full SHA
    b7dd788 View commit details
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

47 changes: 0 additions & 47 deletions .eslintrc.js

This file was deleted.

1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.ts linguist-language=TypeScript
*.js linguist-language=TypeScript
*.html linguist-language=TypeScript
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -54,10 +54,6 @@ typings/
# Yarn Integrity file
.yarn-integrity

# static files directory
static/*
!static/.gitkeep

templates/*
!templates/test.hbs

5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"dbaeumer.vscode-eslint"
]
}
34 changes: 34 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"editor.formatOnSave": false,

// Auto fix

"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never",
"source.fixAll.stylelint": "explicit"
},
"eslint.run": "onType",
"eslint.format.enable": true,
"css.validate": false,
"less.validate": false,

"files.autoSaveDelay": 500,

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml",
"gql",
"graphql"
]
}
188 changes: 188 additions & 0 deletions README-en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# Puppeteer Server

English | [中文](README.md)

<img src="https://github.com/pdsuwwz/puppeteer-server/assets/19891724/86177762-8a97-4656-8ee0-5add61c50237" height="100" align-right />


## 📤 Migrate to Playwright

To experience enhanced features and broader browser support, the entire codebase of the latest version has seamlessly migrated to Playwright.

Playwright repo: [koa-playwright-server](https://github.com/pdsuwwz/koa-playwright-server)

## Introduction

🦩 Koa + ESM + TypeScript + Rollup + Nodemon + Puppeteer + ESLint (v9)

> * Fast Generate into PDF and images from any webpage.
>
> * Support merge multiple webpages into one PDF file, injection of Cookies, Watermark addition and Header and Footer insertion

## ✨ Features

* ✅ Built-in ES Module + TypeScript environment

* 🌈 Separation business logic and Controllers.

* 🛡 Probably the best practice for Puppeteer project.

* 🧩 Configured routing.

* 🚧 Eslint (v9) configuration.

* ⚡ Fast build with Rollup.

* 🔌 Extensible PDF watermark, header and footer.

* 🧲 Supports merging of multiple PDF files.

* 🔥 Based on Nodemon HMR.


## Screenshot

* Merge Combine the two websites into a PDF file
> 📦 See [Merge Test 1](__test__/axios-browser.html), [Merge Test 2](__test__/axios-node.js)

![image](https://user-images.githubusercontent.com/19891724/159743021-e1f9f528-d6d9-4d6b-b63f-4e71c6b72bdb.png)



## 🎯 Prerequisites

Please make sure that [Node.js](https://nodejs.org/) (>= 20.x) is installed on your operating system.

## Project structure

<pre>
├── src
│ ├── controllers/ --- Server controllers
│ ├── services/ --- Server services
│ ├── config.ts --- About Environments variable
│ ├── main.ts --- Entry file
│ └── routes.ts --- Configs for routing controllers <a href="#Routing">👉 Routing</a>
</pre>

## ⚡ Quick Start

### 1. Installation

```bash
pnpm install
```

### 2. Running Development

```bash
pnpm dev
```

### 3. 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`:

* Build

```bash
pnpm build
```

* Run

```bash
pnpm start # PORT is 8080
# or
node dist/bundle.esm.js # PORT is 5000
```

## API

* `GET /image`

Generate screenshot.

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

* `GET /simple-pdf`

Generate pdf.

```bash
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.

```bash
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
```

👆 /pdf request parameters

| Field | Description | Type | Default Value |
| -------- | -------- | -------- | -------- |
| url | Target site url | string ||
| cookies | Generally used as a website that requires login to access, you can add this field | Array<{ name, value, domain }> | [] |
| hasMargin | If this field is set to true, it means that the generated PDF will contain margins | boolean | true |
| isLandscape | Whether the generated PDF is horizontal | boolean | false |
| hiddenWatermark | Whether to hide watermark | boolean | false |
| attachment | Display the custom header and footer, provided that hasMargin is set to true | { header, footer } ||


* `POST /combine-pdf`

Merge multiple PDF files into one file.

See [Merge Test 1](__test__/axios-browser.html), [Merge Test 2](__test__/axios-node.js)

👆 /combine-pdf request parameters

| Field | Description | Type | Default Value |
| -------- | -------- | -------- | -------- |
| pdfList | A collection of target websites, the parameter type is an array, and each item in the array is a parameter required by `/pdf` | Array<{ pdfItem }> | [] |


## 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](src/routes.ts)

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

# License

:v:

[MIT](./LICENSE)


[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fpdsuwwz%2Fpuppeteer-server.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fpdsuwwz%2Fpuppeteer-server?ref=badge_large)

Loading