fix: 修复服务器两个 / 的问题
This commit is contained in:
parent
7e4df5c3e9
commit
a0dc4540ca
|
|
@ -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(/\/+$/, "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user