File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ export type ListenOptions =
7272 & {
7373 remoteAddress ?: string ;
7474 } ;
75- function createOnListen (
75+ export function createOnListen (
7676 basePath : string ,
7777 options : ListenOptions ,
7878) : ( localAddr : Deno . NetAddr ) => void {
Original file line number Diff line number Diff line change 1- import { App , type ListenOptions , setBuildCache } from "../app.ts" ;
1+ import {
2+ App ,
3+ createOnListen ,
4+ type ListenOptions ,
5+ setBuildCache ,
6+ } from "../app.ts" ;
27import { fsAdapter } from "../fs.ts" ;
38import * as path from "@std/path" ;
49import * as colors from "@std/fmt/colors" ;
@@ -181,7 +186,11 @@ export class Builder<State = any> {
181186
182187 const appHandler = app . handler ( ) ;
183188
184- const devApp = new App < State > ( app . config )
189+ // Store original basePath for display purposes
190+ const originalBasePath = app . config . basePath ;
191+
192+ const devConfig = { ...app . config , basePath : "" } ;
193+ const devApp = new App < State > ( devConfig )
185194 . use ( liveReload ( ) )
186195 . use ( devErrorOverlay ( ) )
187196 . use ( automaticWorkspaceFolders ( this . config . root ) )
@@ -200,7 +209,11 @@ export class Builder<State = any> {
200209 // Boot in parallel to spin up the server quicker. We'll hold
201210 // requests until the required assets are processed.
202211 await Promise . all ( [
203- devApp . listen ( options ) ,
212+ devApp . listen ( {
213+ ...options ,
214+ onListen : options . onListen ??
215+ createOnListen ( originalBasePath , options ) ,
216+ } ) ,
204217 this . #build( buildCache , true ) ,
205218 ] ) ;
206219 return ;
Original file line number Diff line number Diff line change @@ -433,7 +433,7 @@ Deno.test({
433433 const tmp = _tmp . dir ;
434434
435435 const app = new App ( { basePath : "/foo/bar" } )
436- . get ( "/" , ( ) => new Response ( "ok " ) )
436+ . get ( "/" , ( ) => new Response ( "root index " ) )
437437 . get ( "/asdf" , ( ) => new Response ( "ok" ) ) ;
438438
439439 const builder = new Builder ( {
@@ -450,10 +450,20 @@ Deno.test({
450450 } ,
451451 } ) ;
452452
453- const res = await fetch ( `${ address } /foo/bar/asdf` ) ;
453+ // Test regular route
454+ const res1 = await fetch ( `${ address } /foo/bar/asdf` ) ;
455+ const text1 = await res1 . text ( ) ;
456+ expect ( text1 ) . toEqual ( "ok" ) ;
454457
455- const text = await res . text ( ) ;
456- expect ( text ) . toEqual ( "ok" ) ;
458+ // Test root index with basePath (without trailing slash)
459+ // This was the main issue - accessing /foo/bar should work
460+ const res2 = await fetch ( `${ address } /foo/bar` ) ;
461+ const text2 = await res2 . text ( ) ;
462+ expect ( res2 . status ) . toEqual ( 200 ) ;
463+ expect ( text2 ) . toEqual ( "root index" ) ;
464+
465+ // Verify original app config is not mutated by dev builder
466+ expect ( app . config . basePath ) . toEqual ( "/foo/bar" ) ;
457467
458468 controller . abort ( ) ;
459469 } ,
You can’t perform that action at this time.
0 commit comments