Packages
Edge Runtime
Deploy Surf to edge runtimes
Edge Runtime#
@surfjs/core v0.2.0 uses the Web Crypto API instead of Node's node:crypto, making it compatible with Vercel Edge Functions, Cloudflare Workers, and any Web Standard runtime.
typescript
// Works in Cloudflare Workers, Vercel Edge, Deno Deploy// No special config needed โ @surfjs/core detects the runtimeย import { createSurf } from '@surfjs/core'import { Hono } from 'hono'ย const surf = await createSurf({ name: 'Edge App', commands: { search: { description: 'Search at the edge', params: { query: { type: 'string', required: true } }, run: async ({ query }) => kv.search(query), // Use edge-native storage }, },})ย const app = new Hono()ย // Mount Surf middleware โ works on the edgeapp.use('/surf/*', async (c) => { const handler = surf.middleware() // Hono-compatible bridge return new Response('...') // see Hono adapter docs})ย export default app๐ก Tip: For Vercel Edge deployments, use
@surfjs/nextwithcreateSurfRouteHandlerand addexport const runtime = 'edge'to your route file.
typescript
// app/api/surf/[...slug]/route.tsimport { createSurf } from '@surfjs/core'import { createSurfRouteHandler } from '@surfjs/next'ย export const runtime = 'edge' // โ Run this route at the Vercel edgeย const surf = await createSurf({ name: 'Edge App', commands: { /* ... */ } })export const { GET, POST } = createSurfRouteHandler(surf)