documentation/docs/25-build-and-deploy/99-writing-adapters.md
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:
// @errors: 2322
// @filename: ambient.d.ts
type AdapterSpecificOptions = any;
// @filename: index.js
// ---cut---
/** @param {AdapterSpecificOptions} options */
export default function (options) {
/** @type {import('@sveltejs/kit').Adapter} */
const adapter = {
name: 'adapter-package-name',
async adapt(builder) {
// adapter implementation
},
async emulate() {
return {
async platform({ config, prerender }) {
// the returned object becomes `event.platform` during dev, build and
// preview. Its shape is that of `App.Platform`
}
}
},
supports: {
read: ({ config, route }) => {
// 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: () => {
// Return `true` if this adapter supports loading `instrumentation.server.js`.
// Return `false if it can't, or throw a descriptive error.
}
}
};
return adapter;
}
Of these, name and adapt are required. emulate and supports are optional.
Within the adapt method, there are a number of things that an adapter should do:
builder.writeClient, builder.writeServer, and builder.writePrerenderedServer from ${builder.getServerDirectory()}/index.jsbuilder.generateManifest({ relativePath })Request if necessary, calls the server.respond(request, { getClientAddress }) function to generate a Response and responds with itplatform option passed to server.respondfetch to work on the target platform, if necessary. SvelteKit provides a @sveltejs/kit/node/polyfills helper for platforms that can use undiciWhere possible, we recommend putting the adapter output under the build/ directory with any intermediate output placed under .svelte-kit/[adapter-name].