Replies: 5 comments 13 replies
-
So just to reboot the conversation: I'd like to devise something that relies on dependency injection (a proper platform abstraction) which would simplify both testing and bootstrapping in general. So here's my current thinking: // Platform features (file IO etc) is made available to Handlers:
type Platform = {
glob: (pattern: string) => FileInfo[];
open: (path: string) => ReadableStream;
// ...
}
interface FileInfo {
path: string;
// ...
}
// Context provides Request-specific dependencies, communication between handlers:
type Context = Record<symbol, unknown>;
// Handlers bootstrap with the Platform, then process Requests and produce Responses:
type Handler = (platform: Platform) => (request: Request, context: Request) => Response; Thoughts? |
Beta Was this translation helpful? Give feedback.
-
I think a full platform standardization might be out of reach today. But there is a proposed web standard for a filesystem API. I'm not very familiar with it but it might be a starting point. |
Beta Was this translation helpful? Give feedback.
-
Can we design an adapter from Koa middleware to Hattip middleware? |
Beta Was this translation helpful? Give feedback.
-
I'm currently really interested in solving this issue about universal middlewares (or at least request handlers). I'm working on Bati which is Vike's new pick-and-choose scaffolder. In Bati, you can choose between multiple server libs, and currently each middleware need to be written manually for each server as there is no common way to represent them. @mindplay-dk I liked the idea of universal handlers, and I think that solving this issue first reduces the scope of maintainability quite drastically in Bati's case. With universal handlers out of the way, writing custom middlewares for each frameworks could be solved by a lib that creates the right middleware for you (like unplugin does for builders). I'll soon try to create an "any server middleware" to "generic handler + context" (and vice-versa) as some kind of POC within NB: Here are the current servers implementations in Bati: |
Beta Was this translation helpful? Give feedback.
-
I created a repository to compile some ideas and some code. Feel free to open discussions are create PRs for specific topics. |
Beta Was this translation helpful? Give feedback.
-
Previous discussion was here: honojs/hono#443
Beta Was this translation helpful? Give feedback.
All reactions