Skip to content

部署到 Cloudflare

Cloudflare Pages

  1. 确保所有 服务器渲染 的路由都使用 Edge Runtime,例如:

    ts
    // app/api/hello/route.ts
    export const runtime = 'edge'
    
    export async function GET() {
      return new Response('Hello, Next.js!')
    }
详细说明
  • 所有 API Routes (route.ts)
  • 使用 Node.js 模块 (fs, path, crypto 等)
  • 服务端数据获取页面 (使用 fetch 等异步操作的 RSC)
  • 使用不兼容 npm 包 (mysql2, mongoose 等需要 Node.js 的包)
  1. 初始设置:

    init settings

  2. 保存并部署。

    此时访问会出现兼容性的错误提示,继续处理。

  3. 设置 “兼容性标志” 为 nodejs_compat

    compatibility flags

  4. 重新部署。

    测试访问。

基于 MIT 许可发布