-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Is your feature request related to a problem? Please describe.
There are a lot of issues that either ask for server side features like SSE, websocket, etc or directly for server side middlewares.
I think the root issue is that the handle hook exposes its own types for request and response, which are not compatible with express middlewares that is the de facto standard in Node.
I get the rationale behind this design, as @Rich-Harris said in #334
it means that the answer to various problems becomes 'use adapter-node, because you can use arbitrary middleware'
However, the current design feels more like making adapter-node a second-class citizen in order to treat every adapter the same.
I recently came across https://github.com/vendia/serverless-express, which seems to contain a solution to this problem.
Describe the solution you'd like
This code converts a request-like object into http.IncomingMessage (there is similar code for http.ServerResponse)
https://github.com/vendia/serverless-express/blob/5cd87c8e7ca3a5e971d26d471cb70a6ac15cc61f/src/request.js#L7-L16
And it's the cornerstone for using middlewares in a serverless environment.
I wonder if it's a good idea to make the handle hook (maybe also endpoints) expose http.IncomingMessage and http.ServerResponse instead? For adaptor-node, the corresponding objects from polka are directly returned, for other adaptors, the aforementioned polyfill is applied.
This should open Svelte Kit to the vast amount of server middlewares that are available.
Describe alternatives you've considered
How important is this feature to you?
Very, not being able use existing middlewares is a deal breaker for many people from the referenced issues.
But it's actually possible to polyfill in userland to use the middlewares.
Additional context