0
# Adapter Configuration
1
2
Configuration options for the SvelteKit Vercel adapter, including serverless functions, edge functions, and image optimization settings.
3
4
## Capabilities
5
6
### Main Configuration Type
7
8
Union type combining serverless and edge configuration options with image optimization.
9
10
```typescript { .api }
11
type Config = (EdgeConfig | ServerlessConfig) & {
12
/**
13
* Image optimization configuration for Vercel's image service
14
* https://vercel.com/docs/build-output-api/v3/configuration#images
15
*/
16
images?: ImagesConfig;
17
};
18
```
19
20
### Serverless Configuration
21
22
Configuration options for deploying to Vercel's serverless functions runtime.
23
24
```typescript { .api }
25
interface ServerlessConfig {
26
/**
27
* Node.js runtime version for serverless functions
28
* @deprecated Use the build environment's Node.js version instead
29
* @default Same as the build environment
30
*/
31
runtime?: `nodejs${number}.x`;
32
33
/**
34
* Vercel regions where the function should be deployed
35
* More info: https://vercel.com/docs/concepts/edge-network/regions
36
*/
37
regions?: string[];
38
39
/**
40
* Maximum execution duration in seconds for the serverless function
41
* Serverless only
42
*/
43
maxDuration?: number;
44
45
/**
46
* Amount of memory (RAM in MB) allocated to the serverless function
47
* Serverless only
48
*/
49
memory?: number;
50
51
/**
52
* If true, this route will always be deployed as its own separate function
53
*/
54
split?: boolean;
55
56
/**
57
* Incremental Static Regeneration configuration
58
* Serverless only
59
* https://vercel.com/docs/concepts/incremental-static-regeneration/overview
60
*/
61
isr?: {
62
/**
63
* Expiration time (in seconds) before cached asset will be re-generated
64
* Setting to false means it will never expire
65
*/
66
expiration: number | false;
67
68
/**
69
* Random token for bypassing cached version via __prerender_bypass=<token> cookie
70
* GET/HEAD requests with x-prerender-revalidate: <token> header force re-validation
71
*/
72
bypassToken?: string;
73
74
/**
75
* Query string parameter names cached independently
76
* Empty array ignores query values, undefined caches each unique query independently
77
* Note: '__pathname' is a reserved parameter and cannot be included
78
*/
79
allowQuery?: string[] | undefined;
80
} | false;
81
}
82
```
83
84
**Usage Examples:**
85
86
```javascript
87
// Basic serverless configuration
88
adapter({
89
runtime: "nodejs20.x",
90
regions: ["iad1", "sfo1"],
91
memory: 512,
92
maxDuration: 30
93
});
94
95
// ISR configuration
96
adapter({
97
runtime: "nodejs20.x",
98
isr: {
99
expiration: 300, // 5 minutes
100
bypassToken: "secret-bypass-token",
101
allowQuery: ["page", "sort"]
102
}
103
});
104
105
// Split functions for different routes
106
adapter({
107
split: true,
108
memory: 1024
109
});
110
```
111
112
#### ISR Validation and Restrictions
113
114
When using ISR configuration, the adapter performs validation to ensure proper functionality:
115
116
**Reserved Parameters:**
117
- `__pathname` is automatically added to the `allowQuery` list and cannot be manually specified
118
- Including `__pathname` in your `allowQuery` array will result in a validation error
119
120
**Runtime Requirements:**
121
- ISR can only be used with Node.js runtimes (`nodejs18.x`, `nodejs20.x`, etc.)
122
- Edge runtime (`runtime: 'edge'`) does not support ISR functionality
123
124
**Error Examples:**
125
126
```javascript
127
// ❌ This will throw an error
128
adapter({
129
isr: {
130
expiration: 300,
131
allowQuery: ["page", "__pathname"] // Error: __pathname is reserved
132
}
133
});
134
135
// ❌ This will throw an error
136
adapter({
137
runtime: "edge", // Error: Edge runtime doesn't support ISR
138
isr: {
139
expiration: 300
140
}
141
});
142
```
143
144
### Edge Configuration (Deprecated)
145
146
⚠️ **DEPRECATED**: Edge runtime configuration is deprecated and will be removed in a future version of adapter-vercel. Use serverless configuration instead.
147
148
Configuration options for deploying to Vercel's edge functions runtime.
149
150
```typescript { .api }
151
/**
152
* @deprecated Edge runtime configuration is deprecated
153
* Will be removed in a future version of adapter-vercel
154
*/
155
interface EdgeConfig {
156
/**
157
* Edge functions runtime identifier
158
*/
159
runtime?: 'edge';
160
161
/**
162
* Deployment regions - array of region codes or 'all' for global deployment
163
* More info: https://vercel.com/docs/concepts/edge-network/regions
164
*/
165
regions?: string[] | 'all';
166
167
/**
168
* List of packages that should not be bundled into the Edge Function
169
* Edge only
170
*/
171
external?: string[];
172
173
/**
174
* If true, this route will always be deployed as its own separate function
175
*/
176
split?: boolean;
177
}
178
```
179
180
**Usage Examples:**
181
182
```javascript
183
// Edge function configuration (DEPRECATED - use serverless instead)
184
adapter({
185
runtime: "edge", // ⚠️ DEPRECATED
186
regions: ["iad1", "fra1"],
187
external: ["some-package"]
188
});
189
190
// Recommended alternative - use serverless configuration:
191
adapter({
192
runtime: "nodejs20.x", // ✅ RECOMMENDED
193
regions: ["iad1", "fra1"]
194
});
195
```
196
197
### Image Configuration
198
199
Settings for Vercel's built-in image optimization service.
200
201
```typescript { .api }
202
interface ImagesConfig {
203
/**
204
* Array of width values for responsive image generation
205
*/
206
sizes: number[];
207
208
/**
209
* Array of allowed domain names for external images
210
*/
211
domains: string[];
212
213
/**
214
* Array of remote pattern objects for more flexible external image matching
215
*/
216
remotePatterns?: RemotePattern[];
217
218
/**
219
* Minimum Cache-Control max-age in seconds for optimized images
220
*/
221
minimumCacheTTL?: number;
222
223
/**
224
* Array of allowed output image formats
225
*/
226
formats?: ImageFormat[];
227
228
/**
229
* Allow potentially unsafe SVG images
230
*/
231
dangerouslyAllowSVG?: boolean;
232
233
/**
234
* Content Security Policy for SVG images when dangerouslyAllowSVG is true
235
*/
236
contentSecurityPolicy?: string;
237
238
/**
239
* Content-Disposition header type for image responses
240
*/
241
contentDispositionType?: string;
242
}
243
244
interface RemotePattern {
245
/**
246
* Protocol for remote image URLs
247
*/
248
protocol?: 'http' | 'https';
249
250
/**
251
* Hostname for remote image URLs (required)
252
*/
253
hostname: string;
254
255
/**
256
* Port for remote image URLs
257
*/
258
port?: string;
259
260
/**
261
* Pathname pattern for remote image URLs
262
*/
263
pathname?: string;
264
}
265
266
type ImageFormat = 'image/avif' | 'image/webp';
267
```
268
269
**Usage Examples:**
270
271
```javascript
272
// Image optimization configuration
273
adapter({
274
images: {
275
sizes: [320, 640, 750, 828, 1080, 1200, 1920, 2048, 3840],
276
domains: ["example.com", "images.example.com"],
277
remotePatterns: [
278
{
279
protocol: "https",
280
hostname: "**.amazonaws.com",
281
pathname: "/uploads/**"
282
}
283
],
284
formats: ["image/avif", "image/webp"],
285
minimumCacheTTL: 60
286
}
287
});
288
```
289
290
### RequestContext Interface
291
292
Context object available in edge functions for advanced functionality.
293
294
```typescript { .api }
295
/**
296
* Extension to the standard Request object passed to every Edge Function
297
* Copy of @vercel/edge RequestContext to avoid package conflicts with @types/node
298
*/
299
interface RequestContext {
300
/**
301
* Method to keep the function running after a response has been sent
302
* Useful for async tasks that should continue after the response
303
*/
304
waitUntil(promise: Promise<unknown>): void;
305
}
306
```
307
308
**Usage Examples:**
309
310
```typescript
311
// Edge function with context usage
312
export default async function handler(request: Request, ctx: RequestContext): Promise<Response> {
313
try {
314
const response = await processRequest(request);
315
316
// Log analytics after response is sent
317
ctx.waitUntil(
318
fetch('https://analytics.example.com/log', {
319
method: 'POST',
320
body: JSON.stringify({ url: request.url, timestamp: Date.now() })
321
})
322
);
323
324
return response;
325
} catch (error) {
326
// Report error to monitoring service
327
ctx.waitUntil(
328
reportError(error, request.url)
329
);
330
331
return new Response('Internal Server Error', { status: 500 });
332
}
333
}
334
```
335
336
## Global Platform Extension
337
338
The adapter extends SvelteKit's global App.Platform interface to provide Vercel-specific context.
339
340
```typescript { .api }
341
declare global {
342
namespace App {
343
export interface Platform {
344
/**
345
* RequestContext is only available in Edge Functions
346
* Provides access to waitUntil and other edge-specific functionality
347
*/
348
context?: RequestContext;
349
}
350
}
351
}
352
```
353
354
**Usage in SvelteKit:**
355
356
```typescript
357
// In a SvelteKit route or hook
358
export async function load({ platform }) {
359
// Edge function context is available
360
if (platform?.context) {
361
platform.context.waitUntil(
362
logRequest(request.url)
363
);
364
}
365
366
return {
367
// route data
368
};
369
}
370
```