diff --git a/.changeset/many-pigs-deliver.md b/.changeset/many-pigs-deliver.md new file mode 100644 index 000000000000..4617dfa1af8a --- /dev/null +++ b/.changeset/many-pigs-deliver.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-netlify': patch +--- + +Add Netlify Functions context as `event.platform.context` diff --git a/packages/adapter-netlify/README.md b/packages/adapter-netlify/README.md index 52979b7bc155..8ba42157d3f0 100644 --- a/packages/adapter-netlify/README.md +++ b/packages/adapter-netlify/README.md @@ -57,7 +57,9 @@ During compilation, redirect rules are automatically appended to your `_redirect ### Using Netlify Functions -[Netlify Functions](https://docs.netlify.com/functions/overview/) can be used alongside your SvelteKit routes. If you would like to add them to your site, you should create a directory for them and add the configuration to your `netlify.toml` file. For example: +With this adapter, SvelteKit endpoints are hosted as [Netlify Functions](https://docs.netlify.com/functions/overview/). Netlify function handlers have additional context, including [Netlify Identity](https://docs.netlify.com/visitor-access/identity/) information. You can access this context via the `event.platform.context` field inside your hooks and endpoints. + +Additionally, you can add your own Netlify functions by creating a directory for them and adding the configuration to your `netlify.toml` file. For example: ```toml [build] diff --git a/packages/adapter-netlify/src/handler.js b/packages/adapter-netlify/src/handler.js index 13eb9175c680..160706c1be2e 100644 --- a/packages/adapter-netlify/src/handler.js +++ b/packages/adapter-netlify/src/handler.js @@ -9,8 +9,8 @@ import { split_headers } from './headers'; export function init(manifest) { const server = new Server(manifest); - return async (event) => { - const rendered = await server.respond(to_request(event)); + return async (event, context) => { + const rendered = await server.respond(to_request(event), { platform: { context } }); const partial_response = { statusCode: rendered.status,