How do you set a an api route to run on the edge and also how do I verify that it actually is?

Just in general I don’t think I understand how to run a nextjs function on the edge with netlify for example I thought that if I did something like this

export const runtime = "edge"

export async function GET(request: Request, response: Response) {
  const session = await withAuth()
  console.log("On Edge session route")
  if (session) {
    return Response.json(session)
  }

  return Response.json({ error: "Unauthorized" }, { status: 401 })
}

Then it would run this on the edge but I see the logs over here

And nothing in the edge function logs, so I guess firstly would I be correct that if it were running on the edge runtime I would see logs in the edge runtime logs not server logs?

This is a Vercel specific feature. That does nothing on Netlify.

1 Like

Thanks for the reply, well that explains a lot.

So how do you get a nextjs route to run on the edge in netlify?

You don’t. All API routes run on Lambda. Only Middleware runs on Edge Functions. If you want, you can deploy separate Netlify Edge Functions to handle your API.

Might be worth editing this page then

This is what I see in the docs: Next.js on Netlify | Netlify Docs

Where are you seeing that?

EDIT: Oh, on OpenNext docs…

EDIT 2: PR Submitted: chore: make docs clearer about Netlify Functions vs Edge Functions provisioning by hrishikesh-k · Pull Request #115 · opennextjs/docs

1 Like