RFC: annotate server environment request entrypoints #22507
Replies: 3 comments
-
|
This generally looks good to me.
There are exceptions to this and I think it's OK for Vite to use a superset of the Rolldown/Rollup API. Might be worth also considering what this would look like if it was included directly in |
Beta Was this translation helpful? Give feedback.
-
👍 I think that's a good assumption, it makes the contract between frameworks and platforms providers easier to understand.
// pseudo code
export default {
fetch() { ... },
node: {
port: 3000,
// Node adapter can use this if it exists instead of wrapping the `fetch` handler
handler(req, res) { ... }
}
}This still respect the
I like this approach, as we can still call |
Beta Was this translation helpful? Give feedback.
-
|
I submitted a PR for this here: #22680 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Motivation
In order to generate the necessary deployment configuration, a platform provider plugin (e.g. Netlify, Cloudflare, Vercel, etc.) must know where to find files that contain the framework’s request handler (in this document I’ll refer to this file as a server request entrypoint).
In the current n·m world, a framework-specific, provider-specific adapter either has programmatic access to this information via its framework-specific adapter interface (for example, see Astro), or it has documented knowledge of this from the framework. This isn't possible in a framework-agnostic plugin.
What I've seen around the ecosystem is reading
config.build.rollupOptions.inputduring the ssr build or hoping there's one bundle element withtype === "chunk" && isEntryin thegenerateBundlehook. This leaky assumption that a bundle entry chunk happens to be a server request entrypoint may hold for some frameworks in some cases, but not all.rollupOptions.inputcan reference multiple bundle entries, some or all of which may not be request entrypoints.In addition, in order to do anything useful with the file, a provider plugin must know how to invoke its request handler and understand the semantics of its responses. In the current n·m world, a framework-specific, provider-specific adapter has documented knowledge of this from the framework (for example, see React Router 7). Each is different, although in the last year or so the ecosystem has been coalescing around the Fetchable interface.
Note
For a much more detailed deep dive into the motivation for this, see #20907. I'll keep it concise here.
This RFC is a concrete proposal to address "need 1" and "need 2" from the above, where there was broad ecosystem alignment on the need and the appropriateness of solving it in Vite core (vitejs/ecosystem#3).
Proposal
Server bundle inputs that are request entrypoint files should be specified as such under
requestEntrypoints. These are implied to be Fetchable modules, unless specified otherwise withtype: 'custom'.Including a key in
requestEntrypointsthat has no matching entry in (normalized)rollupOptions.inputresults in an error.Usage examples
In a metaframework:
In a provider plugin:
Discussion
consumer === 'server'environments.customtype is intentionally opaque. The idea is this elevates the Fetchable convention as the standard signature (our solution to "need 2" here), while generally solving for "need 1" across arbitrary signatures.foo: {}shape may look weird but (1) this RFC suggests supporting an array form['foo'], and (2) this leaves the API open for extension, particularly for the immediate needs of RFC: Expose a server route manifest to allow routing requests to built environments #21212.Beta Was this translation helpful? Give feedback.
All reactions