Skip to content

Lesson 7 of 9 · 22m

Adapters and Deployment: Build for the Platform You Actually Run

What SvelteKit adapters do, how node/static/edge choices change runtime behavior, and the configuration details that bite in production.

SvelteKit does not pretend every deployment target is the same. An adapter takes the framework-neutral build output and packages it for a concrete platform: Node process, static files, serverless functions, Cloudflare Workers, Vercel, Netlify. Choosing one is an operations decision, not just a line in svelte.config.js.

The adapter shapes the runtime

// svelte.config.js
import adapter from "@sveltejs/adapter-node";
export default {
  kit: {
    adapter: adapter({
      out: "build",
      precompress: true,
    }),
  },
};

adapter-node gives you a long-running server you control: process memory, websockets, streaming, background-ish work with caveats, and ordinary reverse-proxy deployment. adapter-static emits files for a CDN. Platform adapters target their provider's function and edge primitives.

Static does not mean "same app, cheaper"

import adapter from "@sveltejs/adapter-static";
export default {
  kit: {
    adapter: adapter({
      pages: "build",
      assets: "build",
      fallback: "200.html",
    }),
  },
};

A static deployment cannot run server load functions or form actions at request time. You either prerender data at build time, call external APIs from the browser, or use platform functions elsewhere. Teams discover this late when they deploy a dashboard statically and every POST becomes a 404.

Environment variables have trust boundaries

SvelteKit separates public and private env access:

import { PUBLIC_API_BASE } from "$env/static/public";
import { PRIVATE_DATABASE_URL } from "$env/static/private";

PUBLIC_ values are shipped to the client. Private imports are forbidden in universal and client code. Use static imports when values are fixed at build time and dynamic env ($env/dynamic/private) when a long-running server must read process configuration at runtime.

Operational details that matter

  • Put a reverse proxy in front of adapter-node and pass X-Forwarded-Proto correctly; cookies marked secure depend on accurate protocol detection.
  • SvelteKit protects form actions against cross-site posts, but that is not a license to ignore CSRF design in custom endpoints.
  • Enable precompression where the platform supports it, but do not double-compress behind a CDN already serving Brotli.
  • Know whether secrets are build-time or runtime. Rotating a build-time secret means rebuilding the artifact.

Field notes

  • adapter-auto is convenient for prototypes and a liability for operational clarity; pin the adapter once the platform is real.
  • A fallback HTML page is for SPA-style client routing. It does not conjure server rendering on static hosting.
  • Edge runtimes are not tiny Node. Native modules, long-lived sockets, and some Node APIs may not exist.
  • Test the production artifact, not only vite dev: adapter behavior, headers, and serialization differences appear after build.

Was this lesson helpful?

Sign in to rate