feat(desktop): proxy realtime requests with runtime headers

This commit is contained in:
Bohdan Triapitsyn
2026-06-30 01:21:42 +03:00
parent 359c73fcf3
commit c10930dfd0
9 changed files with 724 additions and 7 deletions
+21 -2
View File
@@ -84,6 +84,7 @@ import { createGracefulShutdownRuntime } from './lib/opencode/shutdown-runtime.j
import { createProjectConfigRuntime } from './lib/projects/project-config.js';
import { createRemoteClientAuthRuntime } from './lib/client-auth/remote-clients.js';
import { createPreviewProxyRuntime } from './lib/preview/proxy-runtime.js';
import { attachRealtimeProxy } from './lib/realtime-proxy.js';
import { createProxyMiddleware, responseInterceptor } from 'http-proxy-middleware';
import webPush from 'web-push';
@@ -135,9 +136,14 @@ const SSE_PATH_PREFIXES = [
'/api/global/event',
'/api/notifications/stream',
'/api/openchamber/events',
'/api/openchamber/realtime-proxy/sse',
];
function shouldSkipCompression(req, res) {
if (process.env.OPENCHAMBER_RUNTIME === 'desktop') {
return true;
}
if (headerIncludesEventStream(req.headers.accept)) {
return true;
}
@@ -1087,6 +1093,9 @@ async function main(options = {}) {
if (typeof options.getIsWindowFocused === 'function') {
notificationTriggerRuntime.setGetIsWindowFocused(options.getIsWindowFocused);
}
const getDesktopRuntimeConfig = typeof options.getDesktopRuntimeConfig === 'function'
? options.getDesktopRuntimeConfig
: null;
console.log(`Starting OpenChamber on port ${port === 0 ? 'auto' : port}`);
@@ -1132,6 +1141,7 @@ async function main(options = {}) {
}));
expressApp = app;
server = http.createServer(app);
let realtimeProxyRuntime = { stop: () => {} };
const bootstrapResult = bootstrapRuntime.setupBaseRoutes(app, {
process,
@@ -1202,6 +1212,13 @@ async function main(options = {}) {
setAutoAcceptSession,
});
uiAuthController = bootstrapResult.uiAuthController;
realtimeProxyRuntime = attachRealtimeProxy({
app,
server,
getDesktopRuntimeConfig,
getUiAuthController: () => uiAuthController,
isRequestOriginAllowed,
});
const tunnelRuntimeContext = tunnelWiringRuntime.initialize(app, port);
const { tunnelService, startTunnelWithNormalizedRequest } = tunnelRuntimeContext;
@@ -1341,8 +1358,10 @@ async function main(options = {}) {
port: managed ? openCodePort : null,
};
},
stop: (shutdownOptions = {}) =>
gracefulShutdown({ exitProcess: shutdownOptions.exitProcess ?? false })
stop: (shutdownOptions = {}) => {
realtimeProxyRuntime.stop();
return gracefulShutdown({ exitProcess: shutdownOptions.exitProcess ?? false });
}
};
}