@@ -30,7 +30,6 @@ import {
3030 segmentToMiddlewares ,
3131} from "./segments.ts" ;
3232import { isHandlerByMethod , type PageResponse } from "./handlers.ts" ;
33- import { staticFiles } from "./middlewares/static_files.ts" ;
3433
3534// TODO: Completed type clashes in older Deno versions
3635// deno-lint-ignore no-explicit-any
@@ -39,9 +38,6 @@ export const DEFAULT_CONN_INFO: any = {
3938 remoteAddr : { transport : "tcp" , hostname : "localhost" , port : 1234 } ,
4039} ;
4140
42- /** Used to group mounted apps. Only internal */
43- let INTERNAL_ID = 0 ;
44-
4541const DEFAULT_RENDER = < State > ( ) : Promise < PageResponse < State > > =>
4642 // deno-lint-ignore no-explicit-any
4743 Promise . resolve ( { data : { } as any } ) ;
@@ -182,7 +178,6 @@ export class App<State> {
182178 method : Method | "ALL" ;
183179 pattern : string ;
184180 fns : MiddlewareFn < State > [ ] ;
185- unshift : boolean ;
186181 } [ ] = [ ] ;
187182
188183 static {
@@ -343,38 +338,38 @@ export class App<State> {
343338 method : Method | "ALL" ,
344339 path : string ,
345340 fns : MiddlewareFn < State > [ ] ,
346- unshift = false ,
347341 ) {
348342 const segment = getOrCreateSegment < State > ( this . #root, path , false ) ;
349343 const result = segmentToMiddlewares ( segment ) ;
350344
351345 result . push ( ...fns ) ;
352346
353347 const resPath = mergePath ( this . config . basePath , path ) ;
354- this . #addRoute( method , resPath , result , unshift ) ;
348+ this . #addRoute( method , resPath , result ) ;
355349 }
356350
357351 #addRoute(
358352 method : Method | "ALL" ,
359353 path : string ,
360354 fns : MiddlewareFn < State > [ ] ,
361- unshift = false ,
362355 ) {
363- this . #routeDefs. push ( { method, pattern : path , fns, unshift } ) ;
356+ this . #routeDefs. push ( { method, pattern : path , fns } ) ;
364357 }
365358
366359 mountApp ( path : string , app : App < State > ) : this {
367- const segmentPath = mergePath ( path , `/__ ${ INTERNAL_ID ++ } /` ) ;
360+ const segmentPath = mergePath ( "" , path ) ;
368361 const segment = getOrCreateSegment ( this . #root, segmentPath , true ) ;
369362 const fns = segmentToMiddlewares ( segment ) ;
370363
364+ segment . middlewares . push ( ...app . #root. middlewares ) ;
365+
371366 const routes = app . #routeDefs;
372367 for ( let i = 0 ; i < routes . length ; i ++ ) {
373368 const route = routes [ i ] ;
374369
375370 const merged = mergePath ( path , route . pattern ) ;
376371 const mergedFns = [ ...fns , ...route . fns ] ;
377- this . #addRoute( route . method , merged , mergedFns , route . unshift ) ;
372+ this . #addRoute( route . method , merged , mergedFns ) ;
378373 }
379374
380375 app . #islandRegistry. forEach ( ( value , key ) => {
@@ -408,20 +403,22 @@ export class App<State> {
408403 return missingBuildHandler ;
409404 }
410405
411- // Fallthrough
412- this . #addMiddleware(
413- "ALL" ,
414- "*" ,
415- [ ...this . #root. middlewares , staticFiles ( ) ] ,
416- true ,
417- ) ;
418-
419406 for ( let i = 0 ; i < this . #routeDefs. length ; i ++ ) {
420407 const route = this . #routeDefs[ i ] ;
421- this . #router. add ( route . method , route . pattern , route . fns , route . unshift ) ;
408+ if ( route . method === "ALL" ) {
409+ this . #router. add ( "GET" , route . pattern , route . fns ) ;
410+ this . #router. add ( "DELETE" , route . pattern , route . fns ) ;
411+ this . #router. add ( "HEAD" , route . pattern , route . fns ) ;
412+ this . #router. add ( "OPTIONS" , route . pattern , route . fns ) ;
413+ this . #router. add ( "PATCH" , route . pattern , route . fns ) ;
414+ this . #router. add ( "POST" , route . pattern , route . fns ) ;
415+ this . #router. add ( "PUT" , route . pattern , route . fns ) ;
416+ } else {
417+ this . #router. add ( route . method , route . pattern , route . fns ) ;
418+ }
422419 }
423420
424- const rootMiddlewares = this . #root. middlewares ;
421+ const rootMiddlewares = segmentToMiddlewares ( this . #root) ;
425422
426423 return async (
427424 req : Request ,
0 commit comments