Supabase Edge Functions
Using Supabase Edge Functions simple demo to show ping on NextJS /api/ Vs a Supabase Edge Function
Supabase Edge vs Next.js API
Measures client-side roundtrip time to each endpoint (no-store).
Next.js /api/ping
ready
min
—
avg
—
max
—
last: —
Supabase /functions/v1/ping
ready
min
—
avg
—
max
—
last: —
Next.js results
No results yet.
Edge results
Waiting for /functions/v1/ping.
Tip: warm vs cold starts show up as “first run higher, later runs lower”. If you want, we can add a “warm-up ping” step too.
NextJS ApI endpoint looks like this:
src/app/api/ping/route.ts
import { NextResponse } from 'next/server'
export async function GET() {
const start = performance.now()
// Simulate minimal server work (optional)
// await new Promise((r) => setTimeout(r, 1))
const ms = Math.round(performance.now() - start)
return NextResponse.json({
ok: true,
runtime: 'nextjs-api',
ms,
ts: new Date().toISOString(),
})
}
Supabase Edge Function looks like this:
/data/supabase/supabase-joemore-dev/functions/main/index.ts
// /data/supabase/supabase-joemore-dev/functions/main/index.ts
Deno.serve(async (req) => {
const url = new URL(req.url)
// Health endpoint (optional)
if (url.pathname === "/") {
return new Response(JSON.stringify({ ok: true, service: "edge-main" }), {
headers: { "content-type": "application/json" },
})
}
// GET /ping -> used by /functions/v1/ping
if (url.pathname === "/ping" && req.method === "GET") {
const start = performance.now()
const ms = Math.round(performance.now() - start)
return new Response(
JSON.stringify({
ok: true,
runtime: "supabase-edge",
ms,
ts: new Date().toISOString(),
}),
{ headers: { "content-type": "application/json" } }
)
}
return new Response(JSON.stringify({ ok: false, error: "Not found", path: url.pathname }), {
status: 404,
headers: { "content-type": "application/json" },
})
})
To deploy this
cd ~/Develop/ubuntu-home-server/stacks/11-supabase-stacks/joemore-dev/
docker restart supabase-joemore-dev-functions-1
Then simply visit the endpoint: https://api-supabase.joemore.dev/functions/v1/ping