项目文件夹
您已经派生过 wehub-cloud-tpl-static-site-function
44fa265a3e
- buildCommand regenerates public/assets/big.bin (512MiB) at build time - gitignore the generated blob - add a download card at the top of the page, above status/upload
wehub-cloud-tpl-static-site-function
WeHub Cloud 模板:静态站 + /api/cloud/* 函数,带上传 / 下载功能,文件落对象存储,元信息存 PostgreSQL。
资源
| 资源 | 说明 |
|---|---|
public/ |
静态前端,占根路由 /(type=static,outputDirectory=public) |
functions/api/ |
HTTP 函数,入口 index.handler,绑 /api/cloud/* |
| Postgres | 控制台绑定后注入 DATABASE_URL,存元信息 |
| 对象存储 | 控制台绑定后注入 S3_*,存文件本体 |
接口
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | /api/cloud/health |
绑定状态 |
| POST | /api/cloud/uploads |
申请上传:返回 id + presigned PUT URL,DB 写一条 pending 元信息 |
| POST | /api/cloud/uploads/:id/confirm |
上传完成后回填 size / status=ready |
| GET | /api/cloud/uploads |
列出元信息 |
| GET | /api/cloud/uploads/:id |
取单条 + presigned GET 下载 URL |
| DELETE | /api/cloud/uploads/:id |
删对象 + 删元信息 |
流程
- 前端选文件 →
POST /api/cloud/uploads→ 拿到upload_url+id - 前端
PUT upload_url直传对象存储(不经过函数) - 前端
POST /api/cloud/uploads/:id/confirm→ 后端把元信息置为ready - 下载:
GET /api/cloud/uploads/:id→ 拿 presigned GET URL → 浏览器跳转
部署
- 仓库根有
wehub.json,functions/api目录存在。 - 控制台给 Preview 绑定 Postgres 与 对象存储,重新部署后函数才能拿到
DATABASE_URL/S3_*。 - 部署后访问 Preview 根路径即可。
本地
cd functions/api && npm install
# 需要本地 PG / S3 兼容服务,并设置 DATABASE_URL / S3_* 环境变量后才能跑通上传下载