Skip to content

Commit 7259ed6

Browse files
brittneypostmadummdidummRich-HarrisConduitry
authored
Small tweaks to readme (#7498)
* Small tweaks to readme Added some more context around edge functions and examples of how to use `event.platform.context`. * Update packages/adapter-netlify/README.md Co-authored-by: Simon H <[email protected]> * Create wild-lions-care.md * format Co-authored-by: Simon H <[email protected]> Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Conduitry <[email protected]>
1 parent 198f3ba commit 7259ed6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

.changeset/wild-lions-care.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sveltejs/adapter-netlify": patch
3+
---
4+
5+
Add information about edge functions and `event.platform`

packages/adapter-netlify/README.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ New projects will use Node 16 by default. However, if you're upgrading a project
5050

5151
SvelteKit supports the beta release of [Netlify Edge Functions](https://docs.netlify.com/netlify-labs/experimental-features/edge-functions/). If you pass the option `edge: true` to the `adapter` function, server-side rendering will happen in a Deno-based edge function that's deployed close to the site visitor. If set to `false` (the default), the site will deploy to standard Node-based Netlify Functions.
5252

53+
```js
54+
import adapter from '@sveltejs/adapter-netlify';
55+
56+
export default {
57+
kit: {
58+
adapter: adapter({
59+
// will create a Netlify Edge Function using Deno-based
60+
// rather than using standard Node-based functions
61+
edge: true
62+
})
63+
}
64+
};
65+
```
66+
5367
## Netlify alternatives to SvelteKit functionality
5468

5569
You may build your app using functionality provided directly by SvelteKit without relying on any Netlify functionality. Using the SvelteKit versions of these features will allow them to be used in dev mode, tested with integration tests, and to work with other adapters should you ever decide to switch away from Netlify. However, in some scenarios you may find it beneficial to use the Netlify versions of these features. One example would be if you're migrating an app that's already hosted on Netlify to SvelteKit.
@@ -69,7 +83,15 @@ During compilation, redirect rules are automatically appended to your `_redirect
6983

7084
### Using Netlify Functions
7185

72-
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.
86+
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 `+page.server` or `+layout.server` endpoints. These are [serverless functions](https://docs.netlify.com/functions/overview/) when the `edge` property is `false` in the adapter config or [edge functions](https://docs.netlify.com/edge-functions/overview/#app) when it is `true`.
87+
88+
```js
89+
// +page.server.js
90+
export const load = async (event) => {
91+
const context = event.platform.context;
92+
console.log(context); // shows up in your functions log in the Netlify app
93+
};
94+
```
7395

7496
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:
7597

0 commit comments

Comments
 (0)