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

Start

Move an existing app to Scava - Next.js, API routes, Supabase, own login

An app that already runs somewhere else, for example on Vercel with Supabase and a login of its own, can move to Scava as a whole. It does not have to shrink to a demo. Almost every part has a counterpart: the pages become a static build, the API routes become server code, the login and the codes from an authenticator app come from Scava, cron jobs become schedules. This page is the checklist for the agent that does the move. It says what changes, what stays, and what Scava cannot do.

Before you start #

The app fits Scava when the people who use it are known and sign in: colleagues, partners, clients. It cannot move as it is when one of these is essential to it:

If one of these is essential, tell the person before you start, instead of moving a reduced version. When Scava fits lists more cases.

These parts are removed or replaced during the move, because the browser does not load them (see What the browser allows):

What becomes what #

In the app todayOn Scava
Pages rendered by a frameworkA static build, published as a folder
API routes, server actions, middlewareOne fetch() in server/index.js, called by the pages at /api/...
Login, passwords, sessions, password resetRemoved. Scava signs people in, and scava.me() says who it is
Codes from an authenticator appRemoved from the app. The agent turns on the code of Scava (or the owner ticks one box on the app page)
User table and rolesShares, groups and the rules in scava.json
A database with an http API, such as Supabase or FirebaseKept and called from server code, or moved into scava.db
File storage, such as S3 or Supabase Storagescava.files, or kept and served through server code
Environment variables with keysSecrets that the owner sets on the app page
Cron jobsschedules in scava.json
Incoming webhooks, calendar feedswebhooks in scava.json, each with its own key
Push notifications"notifications": true and env.SCAVA.push()
Camera, microphone, location"devices" in scava.json; the browser asks each person
Payment forms, maps, videos, chat widgets from other sites"embeds" in scava.json with their host names
Emailenv.SCAVA.mail() to people with access
Sign-in with another service (OAuth)Its return address points to the app's /api/...
Long jobs: PDFs, Python, ffmpegenv.SCAVA.run()

The pages #

Build the pages the way the framework builds static files, and publish the output folder. Every app has a whole address to itself, so the defaults of the build work, without a base path or prefix.

In Next.js, these parts do not exist after an export, and this replaces them (or keep the server, see Next.js):

The upload check warns when code names other websites. Names inside the framework's own code, such as links to its documentation in error messages, are harmless. A Next.js build made on Windows names some of its prefetch files wrongly, so the test run may list missing files whose names start with __next. The pages work without them.

API routes become server code #

Server code is one object with fetch(request, env) in server/index.js, in the shape of a Cloudflare Worker. Scava sends every request for /api or /api/... there, after it checked the sign-in and the access. See Server code.

// src/server.js
import { GET as listItems, POST as addItem } from '../api/items/route.js';

export default {
  async fetch(request, env) {
    const url = new URL(request.url);
    if (url.pathname === '/api/items' && request.method === 'GET') return listItems(request, env);
    if (url.pathname === '/api/items' && request.method === 'POST') return addItem(request, env);
    return new Response('Not found', { status: 404 });
  },
};

Bundle the server code into one file, with its packages, after the page build: a new build empties the output folder. esbuild also compiles TypeScript: name the entry src/server.ts.

npx esbuild src/server.js --bundle --format=esm --platform=neutral --main-fields=browser,module,main --conditions=workerd,worker,browser --outfile=out/server/index.js

As one script in package.json, with esbuild in the devDependencies:

{
  "scripts": {
    "build": "next build && esbuild src/server.js --bundle --format=esm --platform=neutral --main-fields=browser,module,main --conditions=workerd,worker,browser --outfile=out/server/index.js"
  }
}

Then publish with npx -y scava-ai setup out.

Login, users and roles #

Remove the app's own login completely: sign-in and sign-up pages, password fields, password reset, session cookies, token checks and auth middleware. Scava signs people in with Google or a code by email before they see any page or reach /api. The upload check refuses password fields.

Data: keep the database or move it #

Keep it #

Server code calls the database over its http API. The browser cannot call another site, so each page that read the database directly now calls the app's own /api/..., and server code calls the database. For Supabase:

  1. The owner sets the key as a secret on the app page, bound to the host of the project, for example SUPABASE_KEY for abcdefgh.supabase.co. Agents never handle key values; they tell the owner the name and the host.
  2. Server code uses env.SUPABASE_KEY exactly like the key. Scava puts the real key in when the request leaves for that host:
const res = await fetch('https://abcdefgh.supabase.co/rest/v1/items?select=*', {
  headers: { apikey: env.SUPABASE_KEY, authorization: 'Bearer ' + env.SUPABASE_KEY },
});

The client library @supabase/supabase-js works too, bundled with the command above.

Supabase sees only the server code, not the person behind a request. Row level security that relies on Supabase's own sign-in (auth.uid()) therefore no longer tells people apart. Use a key that may reach what the app needs, and decide in server code with env.SCAVA.me().

A value the code computes with, such as a secret for signing tokens, is a readable secret: the owner sets it without a service. See Secrets and API keys.

Move it into scava.db #

scava.db stores JSON entries in collections. Pages read and write it directly, under the rules in scava.json, with no server code. There is no SQL and no query language: list the entries and filter them. See Database.

Files move the same way, with env.SCAVA.files('name').put(fileName, bytes), up to 25 MB per file. See Files.

Cron jobs, webhooks and feeds #

Notifications and email #

Sign-in with another service #

When the app connects to another service with OAuth, such as a bank, a calendar or a social network:

Size #

A version can hold 50 MB and 2,000 files when published with npx -y scava-ai setup, and 10 MB when an AI passes the files in a chat. Large files such as models are sent to browsers as a stream. Files that change without a new version, such as uploads, belong in scava.files, up to 25 MB each. See Limits.

After the move #

  1. Publish with npx -y scava-ai setup <output folder>. The test run lists errors, blocked calls and missing files, each with a hint.
  2. Ask the owner to set the secrets on the app page, and turn on the code from an authenticator app if the old app had one.
  3. Change the addresses at the other services: webhooks, OAuth return addresses, calendar subscriptions.
  4. Share the app with the people who used it.
  5. Run each schedule once with "Run now" on the app page, and check the server part with npx -y scava-ai server.