metadata
title: Page Shot
emoji: 📈
colorFrom: pink
colorTo: blue
sdk: docker
pinned: false
license: mit
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
Page Screenshot API
A web service that captures screenshots of web pages using Puppeteer.
Features
- Web page screenshot capture
- Customizable dimensions (width/height)
- Adjustable image quality
- Rate limiting for API protection
- CORS enabled for cross-origin requests
API Usage
POST /screenshot
Capture a screenshot of a web page.
Request Body:
{
"url": "https://example.com",
"width": 1920,
"height": 1080,
"quality": 80
}
Parameters:
url
(required): The URL of the webpage to capturewidth
(optional): Screenshot width in pixels (default: 1920, range: 100-4000)height
(optional): Screenshot height in pixels (default: 1080, range: 100-4000)quality
(optional): JPEG quality (default: 80, range: 1-100)
Response: Returns the screenshot as a JPEG image.
GET /
Health check endpoint that returns API status.
Example Usage
curl -X POST https://your-app.railway.app/screenshot \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "width": 1280, "height": 720}' \
--output screenshot.jpg
Rate Limiting
- 100 requests per 15 minutes per IP address
Deployment
This application can be deployed on various platforms:
- Hugging Face Spaces (Docker)
- Railway
- Render.com
- Vercel
For detailed deployment instructions, see DEPLOYMENT_GUIDE.md
.
Railway部署指南
1. 准备部署
确保你的项目包含以下文件:
Dockerfile
- 容器化配置railway.toml
- Railway部署配置package.json
- 依赖和启动脚本
2. 部署到Railway
有两种方式部署到Railway:
方式一:通过GitHub连接(推荐)
- 将代码推送到GitHub仓库
- 访问 Railway.app
- 登录并点击 "New Project"
- 选择 "Deploy from GitHub repo"
- 选择你的仓库
- Railway会自动检测Dockerfile并开始部署
方式二:使用Railway CLI
# 安装Railway CLI
npm install -g @railway/cli
# 登录Railway
railway login
# 初始化项目
railway init
# 部署
railway up
3. 环境变量配置
在Railway控制台的Variables标签中添加:
NODE_ENV=production
PORT
(Railway自动设置,无需手动配置)
4. 资源配置
推荐配置:
- CPU: 1 vCPU
- Memory: 1GB RAM
这些配置已在 railway.toml
中预设。
5. 自定义域名(可选)
在Railway控制台的Settings > Domains中可以:
- 使用Railway提供的免费子域名
- 绑定你自己的域名
6. 监控和日志
- 在Railway控制台的Deployments标签查看部署状态
- 在Metrics标签监控资源使用情况
- 在Variables标签管理环境变量
故障排除
如果部署失败,检查:
- Dockerfile语法是否正确
- package.json中的start脚本是否正确
- 依赖包是否都已安装
- 内存使用是否超出限制
部署后测试
# 健康检查
curl https://your-app.railway.app/
# 截图测试
curl -X POST https://your-app.railway.app/screenshot \
-H "Content-Type: application/json" \
-d '{"url": "https://google.com"}' \
--output test-screenshot.jpg