@@ -37,13 +37,28 @@ export async function actorGateway(
3737 return next ( ) ;
3838 }
3939
40+ // Strip basePath from the request path
41+ let strippedPath = c . req . path ;
42+ if ( runConfig . basePath && strippedPath . startsWith ( runConfig . basePath ) ) {
43+ strippedPath = strippedPath . slice ( runConfig . basePath . length ) ;
44+ // Ensure the path starts with /
45+ if ( ! strippedPath . startsWith ( "/" ) ) {
46+ strippedPath = "/" + strippedPath ;
47+ }
48+ }
49+
4050 // Check if this is a WebSocket upgrade request
4151 if ( c . req . header ( "upgrade" ) === "websocket" ) {
42- return await handleWebSocketGateway ( runConfig , managerDriver , c ) ;
52+ return await handleWebSocketGateway (
53+ runConfig ,
54+ managerDriver ,
55+ c ,
56+ strippedPath ,
57+ ) ;
4358 }
4459
4560 // Handle regular HTTP requests
46- return await handleHttpGateway ( managerDriver , c , next ) ;
61+ return await handleHttpGateway ( managerDriver , c , next , strippedPath ) ;
4762}
4863
4964/**
@@ -53,6 +68,7 @@ async function handleWebSocketGateway(
5368 runConfig : RunConfig ,
5469 managerDriver : ManagerDriver ,
5570 c : HonoContext ,
71+ strippedPath : string ,
5672) {
5773 const upgradeWebSocket = runConfig . getUpgradeWebSocket ?.( ) ;
5874 if ( ! upgradeWebSocket ) {
@@ -100,7 +116,7 @@ async function handleWebSocketGateway(
100116 logger ( ) . debug ( {
101117 msg : "proxying websocket to actor" ,
102118 actorId,
103- path : c . req . path ,
119+ path : strippedPath ,
104120 encoding : encodingRaw ,
105121 } ) ;
106122
@@ -109,8 +125,8 @@ async function handleWebSocketGateway(
109125
110126 // Include query string if present
111127 const pathWithQuery = c . req . url . includes ( "?" )
112- ? c . req . path + c . req . url . substring ( c . req . url . indexOf ( "?" ) )
113- : c . req . path ;
128+ ? strippedPath + c . req . url . substring ( c . req . url . indexOf ( "?" ) )
129+ : strippedPath ;
114130
115131 return await managerDriver . proxyWebSocket (
116132 c ,
@@ -130,6 +146,7 @@ async function handleHttpGateway(
130146 managerDriver : ManagerDriver ,
131147 c : HonoContext ,
132148 next : Next ,
149+ strippedPath : string ,
133150) {
134151 const target = c . req . header ( HEADER_RIVET_TARGET ) ;
135152 const actorId = c . req . header ( HEADER_RIVET_ACTOR ) ;
@@ -145,7 +162,7 @@ async function handleHttpGateway(
145162 logger ( ) . debug ( {
146163 msg : "proxying request to actor" ,
147164 actorId,
148- path : c . req . path ,
165+ path : strippedPath ,
149166 method : c . req . method ,
150167 } ) ;
151168
@@ -156,7 +173,7 @@ async function handleHttpGateway(
156173
157174 // Build the proxy request with the actor URL format
158175 const url = new URL ( c . req . url ) ;
159- const proxyUrl = new URL ( `http://actor${ url . pathname } ${ url . search } ` ) ;
176+ const proxyUrl = new URL ( `http://actor${ strippedPath } ${ url . search } ` ) ;
160177
161178 const proxyRequest = new Request ( proxyUrl , {
162179 method : c . req . raw . method ,
0 commit comments