Skip to content

Commit

Permalink
Docs for writing an adapter API
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jul 7, 2021
1 parent 71480bb commit 6247669
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions documentation/docs/80-adapter-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Writing Adapters
---

We recommend [looking at the source for an adapter](https://github.com/sveltejs/kit/tree/master/packages) to a platform similar to yours and copying it as a starting point.

Adapters must implement the following API:
```
export default function () {
/** @type {import('@sveltejs/kit').Adapter} */
return {
name: '',
async adapt({ utils, config }) {
}
};
}
```

Within the `adapt` method, there are a few things an adapter should do:
- Clear out the build directory
- Provide code that runs:
- Call `init`
- Convert from the patform's request to a SvelteKit request, call `render`, convert from a SveteKit reponse to the platform's
- Adapters typically bundle the output to avoid needing to install dependencies on the target platform, etc.
- Globally shim `fetch` to work on the target platform. SvelteKit provides a `@sveltejs/kit/install-fetch` helper to use `node-fetch`
- Call `prerender`
- Put the user's static files and the generated JS/CSS in the correct location for the target platform

0 comments on commit 6247669

Please sign in to comment.