|
1 年之前 | |
---|---|---|
bin | 1 年之前 | |
web | 1 年之前 | |
.editorconfig | 3 年之前 | |
.gitignore | 1 年之前 | |
Dockerfile | 3 年之前 | |
LICENSE | 3 年之前 | |
README.md | 1 年之前 | |
package.json | 1 年之前 | |
yarn.lock | 1 年之前 |
基于 puppeteer koa 的 pdf、html 生成服务
安装 yarn
npm install -g yarn
安装项目依赖
yarn install
puppeteer 需要安装 chrome,需接入国际互联网。
npx @puppeteer/browsers install chrome@latest
将当前服务 http://localhost:8088 对外提供。
将 /prod-api/* 的请求代理到测试环境,或正式环境。
# 该配置未经测试,仅供参考,请自行配置
location /prod-api/ {
proxy_pass https://www.jianyu360.cn/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
yarn run serve
http://localhost:8088/page_big_pc/#/pdf-create
http://localhost:8088/api/to-pdf/文件名?dir=目录名&url=https://www.baidu.com?search=test
已锁定页面ID选择器,不支持自定义页面生成,仅限 page_big_pc/#/html-report 页面可用
http://localhost:8088/api/to-html/文件名?dir=目录名&url=https://www.baidu.com?search=test
dir: 目录名
width: puppeteer设置 宽度
height: puppeteer设置 高度
... 更多 puppeteer 设置
url: 页面URL(如含有query参数,务必作为最后一个参数,详见代码参数截取逻辑)