Bring your own backend for Vercel Board
TL;DR · AI 摘要
Vercel Board 现支持自定义后端,PostgreSQL 成为首个官方集成方案,开发者可结合 Vercel Blob 和 Vercel Queues 实现完整功能。
核心要点
- 使用 PostgreSQL 作为 Vercel Board 后端需配置 blob 存储和定时任务队列
- Vercel Blob 单文件存储上限为 100MB,支持私有存储
- 需安装 pg、@vercel/blob 和 @vercel/queue 依赖包
结构提纲
按章节快速跳转。
思维导图
用一张图看清主题之间的关系。
查看大纲文本(无障碍 / 无 JS 友好)
- Vercel Board 自定义后端
- PostgreSQL 集成
- blob 存储配置
- 定时任务队列
- Vercel 服务
- Vercel Blob
- Vercel Queues
- 认证方案
- OIDC 默认认证
- 自定义验证
金句 / Highlights
值得收藏与分享的关键句。
PostgreSQL 是首个随 SDK 发布的后端方案,支持 DATABASE_URL 环境变量自动读取
vercelBlob 存储方案单文件最大 100MB,适用于中等规模文件存储需求
通过 experimentalTriggers 配置可实现队列触发,retryAfterSeconds 参数控制重试间隔
为 Vercel Board 自建后端
Vercel Board SDK 和 vercel board 命令现在可以接入你自建的后端。部署在你自己的后端的看板,会通过与 Vercel API 中团队看板相同的 API 提供服务。Postgres 是 SDK 首个内置的后端实现。
使用 postgres() 将看板挂载到 API 路由上。它需要一个用于存储文件的 blob 存储。vercelBlob() 将文件存储在私有的 Vercel Blob 存储中,每个文件最大 100 MB。vercelQueues() 在 Vercel Queues 上运行看板的定时器,比如定时消息。
app/api/board/[[...path]]/route.ts
1
import
{
board
}
from
"@vercel/board"
;
2
import
{
postgres
}
from
"@vercel/board/backend-postgres"
;
3
import
{
vercelBlob
}
from
"@vercel/board/backend-postgres/blob-vercel"
;
4
import
{
vercelQueues
}
from
"@vercel/board/backend-postgres/scheduler-vercel"
;
5
6
export
const
scheduler
=
vercelQueues
(
{
topic
:
"board"
}
)
;
7
export
const
team
=
board
(
{
backend
:
postgres
(
{
blob
:
vercelBlob
(
)
,
scheduler
}
)
}
)
;
8
export
const
GET
=
team
.
fetch
,
POST
=
team
.
fetch
;在 Postgres、Vercel Blob 和 Vercel Queues 上挂载看板
将调度器挂载到自己的路由中,并通过队列主题触发:
app/api/board-scheduler/route.ts
1
export
{
scheduler
as
POST
}
from
"@/app/api/board/[[...path]]/route"
;挂载调度器
vercel.json
1
{
2
"functions"
:
{
3
"app/api/board-scheduler/route.ts"
:
{
4
"experimentalTriggers"
:
[
{
"type"
:
"queue/v2beta"
,
"topic"
:
"board"
,
"retryAfterSeconds"
:
30
}
]
5
}
6
}
7
}从 Vercel Queues 触发调度器
请一并安装 pg、@vercel/blob 和 @vercel/queue。postgres() 会读取 DATABASE_URL 或 POSTGRES_URL,或使用你传入的 connectionString 或 pg 连接池。在首次部署前应用随包提供的模式,并使用提供方的连接池 URL,因为每个实例会打开最多 10 个连接的连接池。
调用者默认通过 OIDC 认证。在 Vercel 上,团队成员和项目自身的部署可以访问,授权允许其他项目和 GitHub Actions 工作流访问。通过传递 authenticate 参数以你自己的方式验证调用者,并在看板不在 Vercel 上运行时设置 url。使用 --url 参数将 vercel board 指向你的路由。
升级到 @vercel/[email protected] 或更高版本以使用 Postgres 后端。更多详情请参阅 Postgres 文档。