If an adapter for your preferred environment doesn’t yet exist, you can build your own. We recommend looking at the source for an adapter to a platform similar to yours and copying it as a starting point.
Adapter packages implement the following API, which creates an Adapter:
A function that is called with the current route config and prerender option
and returns an App.Platform object
({config(parameter)config:any,prerender(parameter)prerender:PrerenderOption}){ // the returned object becomes `event.platform` during dev, build and // preview. Its shape is that of `App.Platform`}}},supports(property)Adapter.supports?:{read?:(details:{config:Record<string,any>;route:{id:string;};})=>boolean;instrumentation?:()=>boolean;}|undefined
Checks called during dev and build to determine whether specific features will work in production with this adapter.
The merged adapter-specific route config exported from the route with export const config
:({config(parameter)config:Record<string,any>,route(parameter)route:{id:string;}})=>{ // Return `true` if the route with the given `config` can use `read` // from `$app/server` in production, return `false` if it can't. // Or throw a descriptive error describing how to configure the deployment},instrumentation(property)instrumentation?:(()=>boolean)|undefined
Test support for instrumentation.server.js. To pass, the adapter must support running instrumentation.server.js prior to the application code.
2.31.0
:()=>{ // Return `true` if this adapter supports loading `instrumentation.server.js`. // Return `false if it can't, or throw a descriptive error.}},vite(property)Adapter.vite?:AdapterViteConfig|((ctx:{config:ValidatedConfig;})=>AdapterViteConfig)|undefined
This function overrides the default behavior during Vite's dev and preview modes
to convert an http.IncomingMessage to a Request object.
To call the original setRequest function, import it from @sveltejs/kit/node.
3.0.0
reference(options(parameter)options:{request:IncomingMessage;response?:ServerResponse;base:string;bodySizeLimit?:number;}){constrequestconstrequest:Request=getRequest(alias)getRequest({request,response,base,bodySizeLimit}:{request:IncomingMessage;response?:ServerResponse;base:string;bodySizeLimit?:number;}):RequestimportgetRequestreference(options(parameter)options:{request:IncomingMessage;response?:ServerResponse;base:string;bodySizeLimit?:number;}); // modify the Request object here if neededreturnrequestconstrequest:Request;},setResponse(property)AdapterViteConfig.setResponse?:((res:ServerResponse,response:Response)=>void)|undefined
This function overrides the default behavior in Vite's dev and preview modes
to write a Response object to a http.ServerResponse.
To call the original setResponse function, import it from @sveltejs/kit/node.
3.0.0
reference(res(parameter)res:ServerResponse<IncomingMessage>,response(parameter)response:Response){ // handle WebSockets here, for examplesetResponse(alias)setResponse(res:ServerResponse,response:Response):voidimportsetResponsereference(res(parameter)res:ServerResponse<IncomingMessage>,response(parameter)response:Response);},plugins(property)AdapterViteConfig.plugins?:Plugin<any>[]|{pre?:Plugin[];post?:Plugin[];}|undefined
Vite plugins injected by the adapter. By default,
they are placed before SvelteKit's plugins.
3.0.0
:{ // add plugins here to integrate with Vitepre(property)pre?:Plugin<any>[]|undefined
Vite plugins placed before any of SvelteKit's own plugins.
3.0.0
:[],post(property)post?:Plugin<any>[]|undefined
Vite plugins placed after any of SvelteKit's own plugins.
3.0.0
:[]}}};returnadapterconstadapter:Adapter
{import('@sveltejs/kit').Adapter}
;}
Of these, name and adapt are required. emulate, vite, and supports are optional.
Within the adapt method, there are a number of things that an adapter should do:
Clear out the build directory
Write SvelteKit output with builder.writeClient, builder.writeServer, and builder.writePrerendered
Output code that:
Imports a server instance generated by ${builder.generateServerInstance()}
Runs await server.init({ env, read })
Listens for requests from the platform, converts them to a standard Request if necessary, calls the server.respond(request, { getClientAddress }) function to generate a Response and responds with it
expose any platform-specific information to SvelteKit via the platform option passed to server.respond
Bundle the output to avoid needing to install dependencies on the target platform, if necessary
Put the user’s static files and the generated JS/CSS in the correct location for the target platform
Where possible, we recommend putting the adapter output under the build/ directory with any intermediate output placed under .svelte-kit/[adapter-name].