fix: 修复服务器两个 / 的问题

This commit is contained in:
claude-code-best
2026-04-19 08:55:55 +08:00
parent 7e4df5c3e9
commit a0dc4540ca
2 changed files with 13 additions and 2 deletions

View File

@@ -18,6 +18,6 @@ export const config = {
} as const;
export function getBaseUrl(): string {
if (config.baseUrl) return config.baseUrl;
return `http://localhost:${config.port}`;
const url = config.baseUrl || `http://localhost:${config.port}`;
return url.replace(/\/+$/, "");
}

View File

@@ -33,6 +33,17 @@ const app = new Hono();
// Middleware
app.use("*", logger());
app.use("*", async (c, next) => {
// Normalize double slashes in path (e.g. //v1/environments/bridge → /v1/environments/bridge)
const path = new URL(c.req.url).pathname;
if (path.includes("//")) {
const normalized = path.replace(/\/+/g, "/");
const url = new URL(c.req.url);
url.pathname = normalized;
return app.fetch(new Request(url.toString(), c.req.raw));
}
await next();
});
app.use("/web/*", cors());
// Health check