fix(notifications): use full URL pathname for proxy path
c.req.path in Hono returns the full path, not the relative path within the sub-router, causing the /api/notifications prefix to be doubled. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
cb784b8102
commit
023a9e7fbd
|
|
@ -13,9 +13,8 @@ export const notificationRouter = new Hono();
|
||||||
|
|
||||||
// Proxy all notification requests to encryptid
|
// Proxy all notification requests to encryptid
|
||||||
notificationRouter.all("/*", async (c) => {
|
notificationRouter.all("/*", async (c) => {
|
||||||
const path = `/api/notifications${c.req.path === "/" ? "" : c.req.path}`;
|
const url = new URL(c.req.url);
|
||||||
const search = new URL(c.req.url).search;
|
const targetUrl = `${ENCRYPTID_URL}${url.pathname}${url.search}`;
|
||||||
const targetUrl = `${ENCRYPTID_URL}${path}${search}`;
|
|
||||||
|
|
||||||
const headers = new Headers(c.req.raw.headers);
|
const headers = new Headers(c.req.raw.headers);
|
||||||
headers.delete("host");
|
headers.delete("host");
|
||||||
|
|
@ -32,8 +31,8 @@ notificationRouter.all("/*", async (c) => {
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error("[notifications proxy] Failed to reach encryptid:", e?.message);
|
console.error("[notifications proxy] Failed to reach encryptid:", e?.message);
|
||||||
// Return safe fallbacks instead of hanging
|
// Return safe fallbacks instead of hanging
|
||||||
if (c.req.path === "/count") return c.json({ unreadCount: 0 });
|
if (url.pathname.endsWith("/count")) return c.json({ unreadCount: 0 });
|
||||||
if (c.req.path === "/") return c.json({ notifications: [] });
|
if (url.pathname === "/api/notifications") return c.json({ notifications: [] });
|
||||||
return c.json({ error: "Notification service unavailable" }, 503);
|
return c.json({ error: "Notification service unavailable" }, 503);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue