-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow passing platform context from adapters #3429
Conversation
🦋 Changeset detectedLatest commit: 983ec4f The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✔️ Deploy Preview for kit-demo canceled. 🔨 Explore the source changes: 983ec4f 🔍 Inspect the deploy log: https://app.netlify.com/sites/kit-demo/deploys/61f20e51b04cd40008d605a8 |
Thank you! I'd personally lean towards creating a new property on response = await app.render({ request, meta: env }); The local development question is a good one, and it's actually an even deeper can of worms — should the adapter try to simulate the environment completely, by e.g. adding web APIs supported by Cloudflare Workers and Deno? should it remove Node built-ins? (It's useful to be able to use All of which is to say that it's probably fine to kick that can down the road for now and address it in a follow-up PR! |
Thanks for the feedback, will update the PR and docs with this approach. I thought about this too but I was afraid adding yet another object passed into the handle hook event could become overbearing, but it also makes a lot of sense to keep them seperate, allowing the developer to make the choice of what to do with it. Another question to raise is whether this should be passed all the way down to endpoints. Separation of concerns, and not forcing the dev to implement Again, probably a better question for a follow up PR :) |
RE the environment point about |
definitely, i think — it's easiest to understand if |
@Rich-Harris @benmccann PR is now ready for review. I am not sure where to put more documentation for the new object, so some guidance there would be appreciated :) Testing with a local repo, I am thinking meta should be made Readonly? Probably want to encourage that only locals is the object that should be changed. |
I'm not in love with the name The other suggestion I would have is to stick the platform request on the "meta" object or whatever we end up calling it. This has been requested several times in |
.changeset/cyan-numbers-change.md
Outdated
'@sveltejs/adapter-node': patch | ||
--- | ||
|
||
Pass `platform` object to SvelteKit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to say in the changelog what it contains? If so, we're presumably want separate changesets for the Cloudflare and Node adapters.
After discussion, we decided it makes more sense to have Though now that I review it more closely, I find myself asking what problem this actually solves. In the Cloudflare Workers case, Do we actually need this? |
Ah, I see there's a difference between old and new-style workers, and it isn't a global if you're using the new kind (which we are) |
Yeah that’s right. For reference for others seeing this later. Env is only global in the current common js cloudflare workers. I the newer ES Module workers, and cloudflare pages, it is only passed through as env in the fetch function call. See
|
Perhaps the node README could have an example with something like passport? I haven’t used a node server for a few years so I don’t know what the cool kids are using these days. |
Co-authored-by: Conduitry <[email protected]>
My inclination is probably just to leave adapter-node unchanged until a use case presents itself. Otherwise we might find we're adding the wrong surface area. Updated the PR |
@Rich-Harris Ben had said on Discord
|
Would be curious to know what these middlewares are doing and whether there's any intrinsic reason it can't be done inside Kit instead. Presumably the middleware in question doesn't have access to anything that isn't represented on the |
This is a draft PR that implements some of the ides in #2426 and #3426. I have only currently implemented passing in a new
platform
object fromadapter/cloudflare-pages
as an example, as it is what I am familiar with. Maintainers more familiar with the other adapters and environments should probably handle them.The main change in this PR allows this in adapters:
The developer can now access
env
from the newplatform
object, which is passed to hooks and endpoints.Doing this PR has raised an important question though.
How should a pattern like this be handled in local development?
Perhaps each adapter could provide a default
platform
that can act as a sort of 'polyfill'. Something like KV and Durable Objects from Cloudflare, or user context from Netlify shouldn't be that hard to shim.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
Waiting on remove hn example from ignore option #3427 to allow changeset generationpnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0Closes #2426