Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/many-pigs-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-netlify': patch
---

Add Netlify Functions Context to Netlify Adapter
4 changes: 3 additions & 1 deletion packages/adapter-netlify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 automatically hosted as [Netlify Functions](https://docs.netlify.com/functions/overview/). Netlify Function handlers have additional context passed to them by Netlify, including Netlify Identity information. You can access this context via the `event.platform.context` field inside of your `hooks` and Endpoint handlers.

Additionally, Netlify Functions can be used alongside your SvelteKit routes. If you would like to add them to your site separately from your Endpoints, you should create a directory for them and add the configuration to your `netlify.toml` file. For example:

```toml
[build]
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-netlify/src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down