@@ -37,13 +37,28 @@ export async function actorGateway(
37
37
return next ( ) ;
38
38
}
39
39
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
+
40
50
// Check if this is a WebSocket upgrade request
41
51
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
+ ) ;
43
58
}
44
59
45
60
// Handle regular HTTP requests
46
- return await handleHttpGateway ( managerDriver , c , next ) ;
61
+ return await handleHttpGateway ( managerDriver , c , next , strippedPath ) ;
47
62
}
48
63
49
64
/**
@@ -53,6 +68,7 @@ async function handleWebSocketGateway(
53
68
runConfig : RunConfig ,
54
69
managerDriver : ManagerDriver ,
55
70
c : HonoContext ,
71
+ strippedPath : string ,
56
72
) {
57
73
const upgradeWebSocket = runConfig . getUpgradeWebSocket ?.( ) ;
58
74
if ( ! upgradeWebSocket ) {
@@ -100,7 +116,7 @@ async function handleWebSocketGateway(
100
116
logger ( ) . debug ( {
101
117
msg : "proxying websocket to actor" ,
102
118
actorId,
103
- path : c . req . path ,
119
+ path : strippedPath ,
104
120
encoding : encodingRaw ,
105
121
} ) ;
106
122
@@ -109,8 +125,8 @@ async function handleWebSocketGateway(
109
125
110
126
// Include query string if present
111
127
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 ;
114
130
115
131
return await managerDriver . proxyWebSocket (
116
132
c ,
@@ -130,6 +146,7 @@ async function handleHttpGateway(
130
146
managerDriver : ManagerDriver ,
131
147
c : HonoContext ,
132
148
next : Next ,
149
+ strippedPath : string ,
133
150
) {
134
151
const target = c . req . header ( HEADER_RIVET_TARGET ) ;
135
152
const actorId = c . req . header ( HEADER_RIVET_ACTOR ) ;
@@ -145,7 +162,7 @@ async function handleHttpGateway(
145
162
logger ( ) . debug ( {
146
163
msg : "proxying request to actor" ,
147
164
actorId,
148
- path : c . req . path ,
165
+ path : strippedPath ,
149
166
method : c . req . method ,
150
167
} ) ;
151
168
@@ -156,7 +173,7 @@ async function handleHttpGateway(
156
173
157
174
// Build the proxy request with the actor URL format
158
175
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 } ` ) ;
160
177
161
178
const proxyRequest = new Request ( proxyUrl , {
162
179
method : c . req . raw . method ,
0 commit comments