You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The core Start fs-based api-routes and middleware API hide away most of h3's API surface and have limited composability. h3 allows the composition of nested h3 instances, each with their own routes and middleware. Currently the user must choose between limited Start API's giving them access to getRequestEvent and native h3 API's without getRequestEvent in the form of:
// @refresh reloadimport{createHandler,StartServer}from"@solidjs/start/server";import{H3}from"h3";import{createNitropage}from"nitropage/server";// Custom h3 app, with full access to h3 APIsconstapp=newH3();// No official access to `getRequestEvent` inside this handlerapp.use(createNitropage().handler);// Nested SolidStart app handlerapp.use(createHandler(()=><StartServerdocument={Document}/>,handlerOptions).handler,);app.use("...something after...");exportdefaultapp;
Suggestion A: Provide experimental access to decorateHandler & decorateMiddleware
decorateHandler and decorateMiddleware currently are internal functions used to create and provide the RequestEvent inside the h3 request lifecycle:
Nitropage middleware (RequestEvent via decorateMiddleware)
Nitropage specific event handlers (RequestEvent via decorateHandler)
SolidStart h3 app
Start specific fs routes and middleware (RequestEvent handling built-in)
Suggestion B: Decouple Start from h3
Way more involved, but maybe the better long-term approach is to fully decouple Start from h3 and let the user choose how the RequestEvent is bound to the request objects of the users server framework of choice. By giving them full control over the RequestEvent binding, they can use the same binding for their non-Start handlers/middleware. E.g. (just a very barebones example)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Challenge
The core Start fs-based api-routes and middleware API hide away most of h3's API surface and have limited composability. h3 allows the composition of nested h3 instances, each with their own routes and middleware. Currently the user must choose between limited Start API's giving them access to
getRequestEventand native h3 API's withoutgetRequestEventin the form of:Suggestion A: Provide experimental access to
decorateHandler&decorateMiddlewaredecorateHandleranddecorateMiddlewarecurrently are internal functions used to create and provide the RequestEvent inside the h3 request lifecycle:solid-start/packages/start/src/server/fetchEvent.ts
Line 32 in a8e5a6d
getRequestEventcapable h3 handlers and middleware wherever they want - so they can have one uniform way to access request information in their whole app. An already existing example of this in the wild can be found here: https://codeberg.org/nitropage/nitropage/src/commit/f20c45edac7419007fd34e89ae34cf24d04310ac/packages/nitropage/src/lib/server/middleware/index.tsx#L19. The code mentioned (in combination with the code above), structures the app as follow:decorateMiddleware)decorateHandler)Suggestion B: Decouple Start from h3
Way more involved, but maybe the better long-term approach is to fully decouple Start from h3 and let the user choose how the RequestEvent is bound to the request objects of the users server framework of choice. By giving them full control over the RequestEvent binding, they can use the same binding for their non-Start handlers/middleware. E.g. (just a very barebones example)
This example even goes one step further and customizes the RequestEvent AsyncContext via: https://hono.dev/docs/middleware/builtin/context-storage
Beta Was this translation helpful? Give feedback.
All reactions