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 edge
app.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/next with createSurfRouteHandler and add export const runtime = 'edge' to your route file.

typescript
// app/api/surf/[...slug]/route.ts
import { 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)