@@ -218,7 +218,7 @@ export function getServerMidFromUnstableMid(
218218) : Array < Middleware < ServerNodeEnv & ServerEnv > > {
219219 return serverMiddleware . map ( middleware => {
220220 return async ( c , next ) => {
221- const context = await createMiddlewareContextFromHono ( c as Context ) ;
221+ const context = await createMiddlewareContextFromHono ( c ) ;
222222
223223 return middleware ( context , next ) ;
224224 } ;
@@ -230,7 +230,7 @@ function isRedirect(headers: Headers, code?: number) {
230230}
231231
232232async function createMiddlewareContextFromHono (
233- c : Context < ServerNodeEnv > ,
233+ c : Context < ServerNodeEnv & ServerEnv > ,
234234) : Promise < UnstableMiddlewareContext > {
235235 const loaderContext = getLoaderCtx ( c as Context ) ;
236236
@@ -276,6 +276,10 @@ async function createMiddlewareContextFromHono(
276276 c . res = newRes ;
277277 } ,
278278
279+ get route ( ) {
280+ return c . get ( 'route' ) ;
281+ } ,
282+
279283 get ( key ) {
280284 return loaderContext . get ( key as string ) ;
281285 } ,
@@ -295,3 +299,15 @@ async function createMiddlewareContextFromHono(
295299 redirect : c . redirect . bind ( c ) ,
296300 } ;
297301}
302+
303+ export function injectRoute ( route : {
304+ entryName : string ;
305+ } ) : Middleware < ServerEnv > {
306+ return async ( c , next ) => {
307+ if ( route && ! c . get ( 'route' ) ) {
308+ c . set ( 'route' , route ) ;
309+ }
310+
311+ await next ( ) ;
312+ } ;
313+ }
0 commit comments