Skip to content

Commit 089fb59

Browse files
Fix dev URL redirect to preserve request path and query
The redirect to the dev server was using config.devUrl.href directly, which always redirected to the dev server root regardless of the incoming request path and query string. Now constructs the redirect URL by combining the request's pathname and search with the dev origin. Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
1 parent e3ac9ed commit 089fb59

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

apps/server/src/http.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ export const staticAndDevRouteLayer = HttpRouter.add(
9090

9191
const config = yield* ServerConfig;
9292
if (config.devUrl) {
93-
return HttpServerResponse.redirect(config.devUrl.href, { status: 302 });
93+
const devTarget = new URL(`${url.pathname}${url.search}`, config.devUrl);
94+
return HttpServerResponse.redirect(devTarget.href, { status: 302 });
9495
}
9596

9697
if (!config.staticDir) {

apps/server/src/server.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
266266
const response = yield* Effect.promise(() => fetch(url, { redirect: "manual" }));
267267

268268
assert.equal(response.status, 302);
269-
assert.equal(response.headers.get("location"), "http://127.0.0.1:5173/");
269+
assert.equal(response.headers.get("location"), "http://127.0.0.1:5173/foo/bar");
270270
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
271271
);
272272

0 commit comments

Comments
 (0)