fix(proxy): forward session cookies in WebSocket proxy request for go2rtc
CD — Kai-Sa-Cam Deployment / deploy (push) Successful in 10s

This commit is contained in:
2026-10-25 14:28:04 +01:00
parent 8a936486a4
commit 64ad63da25
+10 -7
View File
@@ -9,20 +9,16 @@ import { mediaRouter } from "./media.js";
import { talkRouter } from "./talk.js";
import { healthRouter } from "./health.js";
// Use process.cwd() instead of import.meta.url for bundled compatibility
const __dirname = process.cwd();
const app = express();
const PORT = process.env.PORT || 8090;
// Middleware
app.use(express.json({ limit: "10mb" }));
app.use(express.urlencoded({ extended: true }));
// Serve static files (built React app)
app.use(express.static(join(__dirname, "dist")));
// Proxy go2rtc requests
const go2rtcProxy = createProxyMiddleware({
target: process.env.GO2RTC_URL || "http://kai-sa-go2rtc:1984",
changeOrigin: true,
@@ -30,17 +26,24 @@ const go2rtcProxy = createProxyMiddleware({
pathRewrite: {
"^/go2rtc": "",
},
on: {
proxyReqWs: (proxyReq: any, req: any) => {
if (req.headers.cookie) {
proxyReq.setHeader("cookie", req.headers.cookie);
}
},
},
});
app.use("/go2rtc", go2rtcProxy);
// API routes
// API routes[cite: 2]
app.use("/api/recordings", recorderRouter);
app.use("/api/media", mediaRouter);
app.use("/api/talk", talkRouter);
app.use("/api", healthRouter);
// SPA fallback - serve index.html for non-API routes
// SPA fallback - serve index.html for non-API routes[cite: 2]
app.get("*", (req, res, next) => {
if (req.path.startsWith("/api") || req.path.startsWith("/go2rtc")) {
return next();
@@ -56,7 +59,7 @@ server.on("upgrade", (req: any, socket: any, head: any) => {
}
});
// WebSocket server for talk
// WebSocket server for talk[cite: 2]
const wss = new WebSocketServer({ server, path: "/api/talk" });
wss.on("connection", (ws: WebSocket) => {