Skip to content
Scava Docs Sign inGet started

Payments open soon. You can create your account today; choosing a plan and connecting an agent open with checkout, and Scava emails you once when it does.

All chapters

Hosting

Next.js on Scava - server components, server actions, route handlers, middleware

A Next.js app goes online with the same command as any other app. When it uses a server (server components that read data at each request, server actions, route handlers in app/api, middleware), the command builds it on your computer with OpenNext, the adapter Cloudflare maintains for Next.js. The result runs as the app's server code, in its own walled-off worker. An app built with output: 'export' is plain files and goes up as its out folder, see Hosting.

Put it online #

In the folder with package.json, the same as for every app:

npx -y scava-ai setup

Nothing to install or set up before. Your agent runs it as it is.

What happens on Scava #

Who is signed in, the data, keys #

getCloudflareContext() from OpenNext gives the same env as all server code, with env.SCAVA:

import { getCloudflareContext } from "@opennextjs/cloudflare";

export const dynamic = "force-dynamic"; // per person: computed at each request, never at build time

export default async function Page() {
  const { env } = getCloudflareContext();
  const me = await env.SCAVA.me(); // { email, name, role, groups, roles }
  const mine = await env.SCAVA.db("tasks", { as: "me" }).list();
  return <p>{me.email} has {mine.length} tasks</p>;
}

The page cache #

Scava keeps what Next.js caches between requests, with nothing to set up:

The cache lives where the app keeps its data (see Data location) and goes with the app. It is a cache, not data: it does not count against the storage of the plan. One app keeps up to 1 GB and 100,000 entries, one entry up to 10 MB; beyond that the oldest make room. Every new version starts with an empty cache.

A cached page is the same for everyone who opens it. A page that asks who is asking (env.SCAVA.me(), or env.SCAVA.db(..., { as: "me" })) never goes into the cache. If Next.js would share such a page with everyone anyway (with revalidate, or as a static page), Scava does not send it: the visitor gets an error, and the app's problems say to give the page export const dynamic = "force-dynamic". So one person never sees a page made for another.

What does not work #

OpenNext warns that it is not fully compatible with Windows and recommends WSL. Scava's own test app was built on Windows and runs.

Moving from Vercel or Netlify #