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](https://github.com/sveltejs/kit/tree/main/packages) to a platform similar to yours and copying it as a starting point. Adapter packages implement the following API, which creates an `Adapter`: ```js // @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. } }, vite: { plugins: [ // add plugins here to integrate with Vite ] } }; return adapter; } ``` Of these, `name` and `adapt` are required. `emulate`, `vite.plugins` 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 `Server` from `${builder.getServerDirectory()}/index.js` - Instantiates the app with a manifest generated with `builder.generateManifest({ relativePath })` - Listens for requests from the platform, converts them to a standard [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) if necessary, calls the `server.respond(request, { getClientAddress })` function to generate a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/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]`. ## Configuring the development and preview experience By default, SvelteKit runs your server code through a Node.js runtime when running `vite dev` and `vite preview`. You can change this behaviour by adding a Vite plugin that has a `configureServer` and `configurePreviewServer` hook to route requests to [a different runtime](https://vite.dev/guide/api-environment-runtimes). The main Vite server environment SvelteKit uses is named `ssr`. You can change its settings by referencing it in the `config` hook of a Vite plugin. ```js // @errors: 2304 1005 1109 config(userConfig) { userConfig.environments = { ssr: { // ... } } } ``` You can also define a custom server entry during development by adding a Vite plugin which resolves the `sveltekit:server-entry` ID to your own module. ```js // @errors: 1005 1128 { name: 'vite-plugin-name-it-yourself', applyToEnvironment(environment) { return environment.name === 'ssr'; }, resolveId: { filter: { id: /^sveltekit:server-entry$/ }, handler(id) { return this.resolve(import.meta.resolve('./path-to-your-server.js')); } } } ``` This module should instantiate the server with your app's manifest, initialise environment variables and the `read` implementation, and export a `fetch` handler which receives a `Request` and returns a `Response`: ```js import { env } from 'sveltekit:env'; import { Server } from 'sveltekit:server'; import { manifest } from 'sveltekit:server-manifest'; const server = new Server(manifest); await server.init({ env, read: (file) => { /* implement how your platform retrieves file contents */ } }); /** * @param {Request} request * @returns {Promise} */ export async function fetch(request) { return await server.respond(request, { getClientAddress: () => { return request.headers.get('how-your-platform-exposes-the-remote-address') } }); } // Without this, server file changes will invalidate the entire Vite server module graph: import.meta.hot?.accept(); ```