File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ export class App<State> {
243243 fns = middlewares ;
244244 }
245245
246- const segment = getOrCreateSegment ( this . #root, path , false ) ;
246+ const segment = getOrCreateSegment ( this . #root, path , true ) ;
247247 segment . middlewares . push ( ...fns ) ;
248248
249249 return this ;
Original file line number Diff line number Diff line change @@ -1512,3 +1512,37 @@ Deno.test("fsRoutes - warn on _layout handler", async () => {
15121512 expect . any ( String ) ,
15131513 ) ;
15141514} ) ;
1515+
1516+ // Middleware issue in 2.0.0-alpha.40
1517+ Deno . test ( "fsRoutes - call correct middleware" , async ( ) => {
1518+ const server = await createServer < { text : string } > ( {
1519+ "routes/_middleware.ts" : {
1520+ handler : async function middleware ( ctx ) {
1521+ ctx . state . text = "_middleware" ;
1522+ return await ctx . next ( ) ;
1523+ } ,
1524+ } ,
1525+ "routes/index.ts" : {
1526+ default : async ( ctx ) => await new Response ( ctx . state . text ) ,
1527+ } ,
1528+ "routes/admin/_middleware.ts" : {
1529+ handler : async function adminMiddleware ( ctx ) {
1530+ ctx . state . text += "admin/_middleware" ;
1531+ return await ctx . next ( ) ;
1532+ } ,
1533+ } ,
1534+ "routes/foo/index.ts" : {
1535+ handler : ( ctx ) => {
1536+ return new Response ( ctx . state . text ) ;
1537+ } ,
1538+ } ,
1539+ } ) ;
1540+
1541+ let res = await server . get ( "/" ) ;
1542+ let text = await res . text ( ) ;
1543+ expect ( text ) . toEqual ( "_middleware" ) ;
1544+
1545+ res = await server . get ( "/foo" ) ;
1546+ text = await res . text ( ) ;
1547+ expect ( text ) . toEqual ( "_middleware" ) ;
1548+ } ) ;
You can’t perform that action at this time.
0 commit comments