# Deploy SvelteKit on forkrail

> Keep `@sveltejs/adapter-vercel` or `adapter-auto` unchanged. forkrail imports the Build Output directly for SSR, streaming, ISR, image optimization, and skew protection inside your AWS account.

- Framework: SvelteKit
- Category: Websites & full-stack
- Status: Production ready
- Adapter / Preset: @sveltejs/adapter-vercel or adapter-auto
- Runtime: Node.js 24 (arm64) or Static S3
- Detection: package.json (@sveltejs/kit)
- Memory: 1,024 MB recommended for SSR
- URL: https://www.forkrail.com/frameworks/sveltekit

## Capabilities

| Capability | Support | Details |
| --- | --- | --- |
| SSR & streaming | Supported | Full streaming SSR, form actions, hooks, and $env |
| ISR caching | Supported | Per-route config.isr cached in the regional router |
| Image optimization | Supported | Adapter images config served via /_vercel/image |
| Skew protection | Supported | Enabled by default; pins open tabs to their deployment |

## 1. Configure your SvelteKit adapter

If your project already uses `@sveltejs/adapter-vercel` or `@sveltejs/adapter-auto`, nothing needs to change — forkrail sets `VERCEL=1` during builds so `adapter-auto` automatically selects Vercel’s adapter. Projects using `@sveltejs/adapter-static` deploy as zero-Lambda static sites served straight from S3.

**svelte.config.js**

```ts
import adapter from '@sveltejs/adapter-vercel'
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'

export default {
  preprocess: vitePreprocess(),
  kit: {
    adapter: adapter({
      images: {
        sizes: [640, 1080, 1920],
        formats: ['image/avif', 'image/webp'],
      },
    }),
  },
}
```

## 2. Deploy preview & production

Deploy from your terminal or connect the repository in **Settings → Git** for automatic branch previews. Because SSR is CPU-bound, 1,024 MB gives noticeably faster renders than the 640 MB default.

**Deploy SvelteKit with the CLI**

```bash
# Set recommended memory once for the project
forkrail project my-svelte-app --memory 1024

# Deploy a preview URL
forkrail deploy

# Ship to production
forkrail deploy --prod
```

## 3. ISR, split routes & client IP

Per-route `export const config` works as written for ISR (`expiration`, `bypassToken`, `allowQuery`), `memory`, and `maxDuration`. `event.getClientAddress()` always returns the visitor’s real IP (forkrail strips spoofed `x-forwarded-for` headers at the router).

**src/routes/blog/[slug]/+page.server.ts**

```ts
export const config = {
  isr: {
    expiration: 60,
  },
}

export async function load({ params }) {
  return { slug: params.slug, renderedAt: new Date().toISOString() }
}
```

> **Shared function memory for split routes:** With `split: true`, forkrail packs all route functions into one shared Lambda function sized to the largest `memory` requested while enforcing each route’s own `maxDuration` at the router. Files read with SvelteKit’s `read()` are bundled automatically.

## 4. Environment variables & AWS access

Add runtime secrets (`$env/dynamic/private`) and build-time variables (`$env/static/public`) through **Settings → Environment Variables** or `forkrail env add`. To reach S3, DynamoDB, or Bedrock without static IAM keys, attach an IAM role to the project (`forkrail project my-svelte-app --role my-app-role`).

## Related documentation

- [Image optimization](https://www.forkrail.com/docs/image-optimization.md)
- [Redirects, rewrites & headers](https://www.forkrail.com/docs/routing.md)
- [Environment variables](https://www.forkrail.com/docs/environment-variables.md)
