InvoiceToTable 文档

部署指南

将 InvoiceToTable 部署到生产环境。

前提条件

部署前确保你有:

  • PostgreSQL 数据库(Supabase、Neon 或 Vercel Postgres)
  • 火山引擎 API Key
  • Creem 账号和 API Key
  • Resend API Key
  • (可选)Google OAuth 凭据
  • (可选)S3 兼容存储

部署到 Vercel

1. 推送到 GitHub

git push origin main

2. 在 Vercel 导入

  1. 访问 vercel.com
  2. 导入你的 GitHub 仓库
  3. 设置所有环境变量(参见环境变量
  4. 部署

3. 数据库迁移

首次部署后:

pnpm db:push

4. 配置 Webhook

在 Creem Dashboard 中设置 webhook URL:

https://your-domain.com/api/payments/creem/webhook

5. 设置定时任务

建议至少配置以下几个受保护的 cron 入口:

curl -H "Authorization: Bearer YOUR_CRON_SECRET" \
  https://your-domain.com/api/cron/subscription-grants

curl -H "Authorization: Bearer YOUR_CRON_SECRET" \
  https://your-domain.com/api/cron/invoice-document-worker

curl -H "Authorization: Bearer YOUR_CRON_SECRET" \
  https://your-domain.com/api/cron/cleanup-expired-batches

curl -H "Authorization: Bearer YOUR_RUNTIME_LOG_API_KEY" \
  "https://your-domain.com/api/runtime-logs?levels=error&limit=100"

如果你要在生产环境稳定使用 RUNTIME_LOG_DIR,部署目标必须有持久磁盘或挂载卷。纯 serverless 实例通常只能保留单实例的临时本地日志。

在 Vercel 上添加到 vercel.json

{
  "crons": [
    {
      "path": "/api/cron/subscription-grants",
      "schedule": "0 * * * *"
    },
    {
      "path": "/api/cron/invoice-document-worker",
      "schedule": "*/1 * * * *"
    },
    {
      "path": "/api/cron/cleanup-expired-batches",
      "schedule": "15 2 * * *"
    }
  ]
}

6. 创建管理员账户

ADMIN_EMAIL=admin@example.com pnpm admin:setup

7. 验证环境

确保生产环境 .env 的以下值正确:

  • BETTER_AUTH_URL — 实际域名
  • NEXT_PUBLIC_APP_URL — 实际域名
  • RESEND_FROM_EMAIL — 已验证的域名发件人

部署后检查清单

  • 数据库已迁移
  • Creem 中已配置 Webhook URL
  • 积分发放、文档处理、清理三个定时任务已设置
  • 管理员账户已创建
  • Resend 中已验证发件域名
  • OAuth 重定向 URI 已更新为生产域名
  • 分析工具 Key 已配置(PostHog、GA、Clarity)

On this page