Update README.md
Browse files
README.md
CHANGED
@@ -9,3 +9,141 @@ license: mit
|
|
9 |
---
|
10 |
|
11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
---
|
10 |
|
11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
12 |
+
|
13 |
+
# Page Screenshot API
|
14 |
+
|
15 |
+
A web service that captures screenshots of web pages using Puppeteer.
|
16 |
+
|
17 |
+
## Features
|
18 |
+
- Web page screenshot capture
|
19 |
+
- Customizable dimensions (width/height)
|
20 |
+
- Adjustable image quality
|
21 |
+
- Rate limiting for API protection
|
22 |
+
- CORS enabled for cross-origin requests
|
23 |
+
|
24 |
+
## API Usage
|
25 |
+
|
26 |
+
### POST /screenshot
|
27 |
+
|
28 |
+
Capture a screenshot of a web page.
|
29 |
+
|
30 |
+
**Request Body:**
|
31 |
+
```json
|
32 |
+
{
|
33 |
+
"url": "https://example.com",
|
34 |
+
"width": 1920,
|
35 |
+
"height": 1080,
|
36 |
+
"quality": 80
|
37 |
+
}
|
38 |
+
```
|
39 |
+
|
40 |
+
**Parameters:**
|
41 |
+
- `url` (required): The URL of the webpage to capture
|
42 |
+
- `width` (optional): Screenshot width in pixels (default: 1920, range: 100-4000)
|
43 |
+
- `height` (optional): Screenshot height in pixels (default: 1080, range: 100-4000)
|
44 |
+
- `quality` (optional): JPEG quality (default: 80, range: 1-100)
|
45 |
+
|
46 |
+
**Response:**
|
47 |
+
Returns the screenshot as a JPEG image.
|
48 |
+
|
49 |
+
### GET /
|
50 |
+
|
51 |
+
Health check endpoint that returns API status.
|
52 |
+
|
53 |
+
## Example Usage
|
54 |
+
|
55 |
+
```bash
|
56 |
+
curl -X POST https://your-app.railway.app/screenshot \
|
57 |
+
-H "Content-Type: application/json" \
|
58 |
+
-d '{"url": "https://example.com", "width": 1280, "height": 720}' \
|
59 |
+
--output screenshot.jpg
|
60 |
+
```
|
61 |
+
|
62 |
+
## Rate Limiting
|
63 |
+
|
64 |
+
- 100 requests per 15 minutes per IP address
|
65 |
+
|
66 |
+
## Deployment
|
67 |
+
|
68 |
+
This application can be deployed on various platforms:
|
69 |
+
- Hugging Face Spaces (Docker)
|
70 |
+
- Railway
|
71 |
+
- Render.com
|
72 |
+
- Vercel
|
73 |
+
|
74 |
+
For detailed deployment instructions, see `DEPLOYMENT_GUIDE.md`.
|
75 |
+
|
76 |
+
## Railway部署指南
|
77 |
+
|
78 |
+
### 1. 准备部署
|
79 |
+
确保你的项目包含以下文件:
|
80 |
+
- `Dockerfile` - 容器化配置
|
81 |
+
- `railway.toml` - Railway部署配置
|
82 |
+
- `package.json` - 依赖和启动脚本
|
83 |
+
|
84 |
+
### 2. 部署到Railway
|
85 |
+
有两种方式部署到Railway:
|
86 |
+
|
87 |
+
#### 方式一:通过GitHub连接(推荐)
|
88 |
+
1. 将代码推送到GitHub仓库
|
89 |
+
2. 访问 [Railway.app](https://railway.app)
|
90 |
+
3. 登录并点击 "New Project"
|
91 |
+
4. 选择 "Deploy from GitHub repo"
|
92 |
+
5. 选择你的仓库
|
93 |
+
6. Railway会自动检测Dockerfile并开始部署
|
94 |
+
|
95 |
+
#### 方式二:使用Railway CLI
|
96 |
+
```bash
|
97 |
+
# 安装Railway CLI
|
98 |
+
npm install -g @railway/cli
|
99 |
+
|
100 |
+
# 登录Railway
|
101 |
+
railway login
|
102 |
+
|
103 |
+
# 初始化项目
|
104 |
+
railway init
|
105 |
+
|
106 |
+
# 部署
|
107 |
+
railway up
|
108 |
+
```
|
109 |
+
|
110 |
+
### 3. 环境变量配置
|
111 |
+
在Railway控制台的Variables标签中添加:
|
112 |
+
- `NODE_ENV=production`
|
113 |
+
- `PORT` (Railway自动设置,无需手动配置)
|
114 |
+
|
115 |
+
### 4. 资源配置
|
116 |
+
推荐配置:
|
117 |
+
- CPU: 1 vCPU
|
118 |
+
- Memory: 1GB RAM
|
119 |
+
|
120 |
+
这些配置已在 `railway.toml` 中预设。
|
121 |
+
|
122 |
+
### 5. 自定义域名(可选)
|
123 |
+
在Railway控制台的Settings > Domains中可以:
|
124 |
+
- 使用Railway提供的免费子域名
|
125 |
+
- 绑定你自己的域名
|
126 |
+
|
127 |
+
### 6. 监控和日志
|
128 |
+
- 在Railway控制台的Deployments标签查看部署状态
|
129 |
+
- 在Metrics标签监控资源使用情况
|
130 |
+
- 在Variables标签管理环境变量
|
131 |
+
|
132 |
+
### 故障排除
|
133 |
+
如果部署失败,检查:
|
134 |
+
1. Dockerfile语法是否正确
|
135 |
+
2. package.json中的start脚本是否正确
|
136 |
+
3. 依赖包是否都已安装
|
137 |
+
4. 内存使用是否超出限制
|
138 |
+
|
139 |
+
### 部署后测试
|
140 |
+
```bash
|
141 |
+
# 健康检查
|
142 |
+
curl https://your-app.railway.app/
|
143 |
+
|
144 |
+
# 截图测试
|
145 |
+
curl -X POST https://your-app.railway.app/screenshot \
|
146 |
+
-H "Content-Type: application/json" \
|
147 |
+
-d '{"url": "https://google.com"}' \
|
148 |
+
--output test-screenshot.jpg
|
149 |
+
```
|