From c9ee636a3def533fb6e6565b4f66a8305f3a0e83 Mon Sep 17 00:00:00 2001 From: Jake Sandler Date: Sun, 27 Feb 2022 14:15:27 -0500 Subject: [PATCH 1/5] Add Netlify Functions Context to Netlify Adapter --- .changeset/many-pigs-deliver.md | 5 +++++ packages/adapter-netlify/src/handler.js | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/many-pigs-deliver.md diff --git a/.changeset/many-pigs-deliver.md b/.changeset/many-pigs-deliver.md new file mode 100644 index 000000000000..07e8e5a760f5 --- /dev/null +++ b/.changeset/many-pigs-deliver.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-netlify': minor +--- + +Add Netlify Functions Context to Netlify Adapter 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, From 396f83dbe8f029b91b6bb1cd29cbe3e7c09bc5f3 Mon Sep 17 00:00:00 2001 From: Jake Sandler Date: Sun, 27 Feb 2022 16:52:27 -0500 Subject: [PATCH 2/5] change to patch and update readme --- .changeset/many-pigs-deliver.md | 2 +- packages/adapter-netlify/README.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.changeset/many-pigs-deliver.md b/.changeset/many-pigs-deliver.md index 07e8e5a760f5..9269fde5d803 100644 --- a/.changeset/many-pigs-deliver.md +++ b/.changeset/many-pigs-deliver.md @@ -1,5 +1,5 @@ --- -'@sveltejs/adapter-netlify': minor +'@sveltejs/adapter-netlify': patch --- Add Netlify Functions Context to Netlify Adapter diff --git a/packages/adapter-netlify/README.md b/packages/adapter-netlify/README.md index 52979b7bc155..d168e1260e48 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 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] From 78af2c434849c486fe57ec43ce6d1e4f9e8b6c3a Mon Sep 17 00:00:00 2001 From: Jake Sandler Date: Sun, 27 Feb 2022 20:51:57 -0500 Subject: [PATCH 3/5] fix lint --- packages/adapter-netlify/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/adapter-netlify/README.md b/packages/adapter-netlify/README.md index d168e1260e48..50ba2f802894 100644 --- a/packages/adapter-netlify/README.md +++ b/packages/adapter-netlify/README.md @@ -57,7 +57,7 @@ During compilation, redirect rules are automatically appended to your `_redirect ### Using Netlify Functions -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. +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: From 8a409e515646ae8e2790b2b08408e4d222ae9ff9 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 28 Feb 2022 10:08:03 -0500 Subject: [PATCH 4/5] Update packages/adapter-netlify/README.md --- packages/adapter-netlify/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/adapter-netlify/README.md b/packages/adapter-netlify/README.md index 50ba2f802894..8ba42157d3f0 100644 --- a/packages/adapter-netlify/README.md +++ b/packages/adapter-netlify/README.md @@ -57,9 +57,9 @@ During compilation, redirect rules are automatically appended to your `_redirect ### Using Netlify Functions -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. +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, 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: +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] From b92064ede796a26a43b04f1a109eeb1b976a84a4 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 28 Feb 2022 10:11:31 -0500 Subject: [PATCH 5/5] Update many-pigs-deliver.md --- .changeset/many-pigs-deliver.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/many-pigs-deliver.md b/.changeset/many-pigs-deliver.md index 9269fde5d803..4617dfa1af8a 100644 --- a/.changeset/many-pigs-deliver.md +++ b/.changeset/many-pigs-deliver.md @@ -2,4 +2,4 @@ '@sveltejs/adapter-netlify': patch --- -Add Netlify Functions Context to Netlify Adapter +Add Netlify Functions context as `event.platform.context`