File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,6 +69,8 @@ export type ListenOptions =
6969 >
7070 & {
7171 remoteAddress ?: string ;
72+ /** Base path to display in startup message (defaults to config.basePath) */
73+ displayBasePath ?: string ;
7274 } ;
7375function createOnListen (
7476 basePath : string ,
@@ -446,7 +448,8 @@ export class App<State> {
446448 */
447449 async listen ( options : ListenOptions = { } ) : Promise < void > {
448450 if ( ! options . onListen ) {
449- options . onListen = createOnListen ( this . config . basePath , options ) ;
451+ const displayBasePath = options . displayBasePath ?? this . config . basePath ;
452+ options . onListen = createOnListen ( displayBasePath , options ) ;
450453 }
451454
452455 const handler = this . handler ( ) ;
Load diff This file was deleted.
Original file line number Diff line number Diff line change @@ -183,6 +183,9 @@ export class Builder<State = any> {
183183
184184 const appHandler = app . handler ( ) ;
185185
186+ // Store original basePath for display purposes
187+ const originalBasePath = app . config . basePath ;
188+
186189 const devConfig = { ...app . config , basePath : "/" } ;
187190 const devApp = new App < State > ( devConfig )
188191 . use ( liveReload ( ) )
@@ -203,7 +206,7 @@ export class Builder<State = any> {
203206 // Boot in parallel to spin up the server quicker. We'll hold
204207 // requests until the required assets are processed.
205208 await Promise . all ( [
206- devApp . listen ( options ) ,
209+ devApp . listen ( { ... options , displayBasePath : originalBasePath } ) ,
207210 this . #build( buildCache , true ) ,
208211 ] ) ;
209212 return ;
Original file line number Diff line number Diff line change @@ -397,7 +397,7 @@ Deno.test({
397397 const tmp = _tmp . dir ;
398398
399399 const app = new App ( { basePath : "/foo/bar" } )
400- . get ( "/" , ( ) => new Response ( "ok " ) )
400+ . get ( "/" , ( ) => new Response ( "root index " ) )
401401 . get ( "/asdf" , ( ) => new Response ( "ok" ) ) ;
402402
403403 const builder = new Builder ( {
@@ -414,10 +414,17 @@ Deno.test({
414414 } ,
415415 } ) ;
416416
417- const res = await fetch ( `${ address } /foo/bar/asdf` ) ;
417+ // Test regular route
418+ const res1 = await fetch ( `${ address } /foo/bar/asdf` ) ;
419+ const text1 = await res1 . text ( ) ;
420+ expect ( text1 ) . toEqual ( "ok" ) ;
418421
419- const text = await res . text ( ) ;
420- expect ( text ) . toEqual ( "ok" ) ;
422+ // Test root index with basePath (without trailing slash)
423+ // This was the main issue - accessing /foo/bar should work
424+ const res2 = await fetch ( `${ address } /foo/bar` ) ;
425+ const text2 = await res2 . text ( ) ;
426+ expect ( res2 . status ) . toEqual ( 200 ) ;
427+ expect ( text2 ) . toEqual ( "root index" ) ;
421428
422429 controller . abort ( ) ;
423430 } ,
Original file line number Diff line number Diff line change @@ -6,8 +6,9 @@ import { ErrorOverlay } from "./overlay.tsx";
66
77export function devErrorOverlay < T > ( ) : Middleware < T > {
88 return async ( ctx ) => {
9- const { config, url } = ctx ;
10- if ( url . pathname === config . basePath + DEV_ERROR_OVERLAY_URL ) {
9+ const { url } = ctx ;
10+ // In dev mode, basePath is always "/" so we check the URL directly
11+ if ( url . pathname === DEV_ERROR_OVERLAY_URL ) {
1112 return ctx . render ( < ErrorOverlay url = { url } /> ) ;
1213 }
1314
Original file line number Diff line number Diff line change @@ -6,11 +6,10 @@ export function liveReload<T>(): Middleware<T> {
66 const revision = Date . now ( ) ;
77
88 return ( ctx ) => {
9- const { config , req, url } = ctx ;
9+ const { req, url } = ctx ;
1010
11- const aliveUrl = config . basePath + ALIVE_URL ;
12-
13- if ( url . pathname === aliveUrl ) {
11+ // In dev mode, basePath is always "/" so we check the URL directly
12+ if ( url . pathname === ALIVE_URL ) {
1413 if ( req . headers . get ( "upgrade" ) !== "websocket" ) {
1514 return new Response ( null , { status : 501 } ) ;
1615 }
You can’t perform that action at this time.
0 commit comments