Skip to content

Commit a0dc454

Browse files
fix: 修复服务器两个 / 的问题
1 parent 7e4df5c commit a0dc454

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

packages/remote-control-server/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ export const config = {
1818
} as const;
1919

2020
export function getBaseUrl(): string {
21-
if (config.baseUrl) return config.baseUrl;
22-
return `http://localhost:${config.port}`;
21+
const url = config.baseUrl || `http://localhost:${config.port}`;
22+
return url.replace(/\/+$/, "");
2323
}

packages/remote-control-server/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ const app = new Hono();
3333

3434
// Middleware
3535
app.use("*", logger());
36+
app.use("*", async (c, next) => {
37+
// Normalize double slashes in path (e.g. //v1/environments/bridge → /v1/environments/bridge)
38+
const path = new URL(c.req.url).pathname;
39+
if (path.includes("//")) {
40+
const normalized = path.replace(/\/+/g, "/");
41+
const url = new URL(c.req.url);
42+
url.pathname = normalized;
43+
return app.fetch(new Request(url.toString(), c.req.raw));
44+
}
45+
await next();
46+
});
3647
app.use("/web/*", cors());
3748

3849
// Health check

0 commit comments

Comments
 (0)