Fix dev TrackerHub transport

This commit is contained in:
2026-05-06 23:55:18 +03:00
parent f0244d20b8
commit 6a3c8f2558
3 changed files with 66 additions and 3 deletions
+27
View File
@@ -142,6 +142,23 @@ app.use(["/api", "/flights"], (req, res) => {
}
});
function normalizeTrackerCookie(cookie) {
if (!cookie.startsWith("signal-id=")) return cookie;
const parts = cookie
.split(";")
.map((part) => part.trim())
.filter(
(part) =>
part.length > 0 &&
!part.toLowerCase().startsWith("domain=") &&
!part.toLowerCase().startsWith("path=") &&
!part.toLowerCase().startsWith("samesite="),
);
return [...parts, "Path=/tracker/hub", "SameSite=Lax"].join("; ");
}
// --- SignalR TrackerHub proxy ---
// Browser-direct localhost → platform.test.aeroflot.ru fails CORS. Keep the
// hub same-origin in development and let proxy-helper / gost route the
@@ -153,6 +170,16 @@ const trackerProxy = createProxyMiddleware({
ws: true,
logLevel: "warn",
pathRewrite: (path) => `/tracker${path}`,
on: {
proxyRes(proxyRes) {
const setCookie = proxyRes.headers["set-cookie"];
if (Array.isArray(setCookie)) {
proxyRes.headers["set-cookie"] = setCookie.map(normalizeTrackerCookie);
} else if (typeof setCookie === "string") {
proxyRes.headers["set-cookie"] = normalizeTrackerCookie(setCookie);
}
},
},
...(SYSTEM_PROXY ? { agent: new HttpsProxyAgent(SYSTEM_PROXY) } : {}),
});
app.use("/tracker", trackerProxy);