Skip to content

Commit 8c08aa5

Browse files
Add Netlify Functions Context to Netlify Adapter (#4145)
* Add Netlify Functions Context to Netlify Adapter * change to patch and update readme * fix lint * Update packages/adapter-netlify/README.md * Update many-pigs-deliver.md Co-authored-by: Rich Harris <[email protected]>
1 parent 9d3b6c4 commit 8c08aa5

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.changeset/many-pigs-deliver.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-netlify': patch
3+
---
4+
5+
Add Netlify Functions context as `event.platform.context`

packages/adapter-netlify/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ During compilation, redirect rules are automatically appended to your `_redirect
5757

5858
### Using Netlify Functions
5959

60-
[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:
60+
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.
61+
62+
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:
6163

6264
```toml
6365
[build]

packages/adapter-netlify/src/handler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { split_headers } from './headers';
99
export function init(manifest) {
1010
const server = new Server(manifest);
1111

12-
return async (event) => {
13-
const rendered = await server.respond(to_request(event));
12+
return async (event, context) => {
13+
const rendered = await server.respond(to_request(event), { platform: { context } });
1414

1515
const partial_response = {
1616
statusCode: rendered.status,

0 commit comments

Comments
 (0)