diff --git a/typescript/fiddle-proxy/server.js b/typescript/fiddle-proxy/server.js index ccc7b469d..959cb4340 100644 --- a/typescript/fiddle-proxy/server.js +++ b/typescript/fiddle-proxy/server.js @@ -87,6 +87,7 @@ app.use( for (const [header, value] of Object.entries(headers)) { proxyReq.setHeader(header, value) } + proxyReq.removeHeader('origin') } catch (err) { // This is not console.warn because it's not important console.log('baml-original-url is not parsable', err) diff --git a/typescript/vscode-ext/packages/vscode/src/extension.ts b/typescript/vscode-ext/packages/vscode/src/extension.ts index 68d512969..64b59c11e 100644 --- a/typescript/vscode-ext/packages/vscode/src/extension.ts +++ b/typescript/vscode-ext/packages/vscode/src/extension.ts @@ -203,9 +203,9 @@ export function activate(context: vscode.ExtensionContext) { // Extract the original target URL from the custom header let originalUrl = req.headers['baml-original-url'] if (typeof originalUrl === 'string') { + // For some reason, Node doesn't like deleting headers in the proxyReq function. delete req.headers['baml-original-url'] - - req.headers['origin'] = `http://localhost:${port}` + delete req.headers['origin'] // Ensure the URL does not end with a slash if (originalUrl.endsWith('/')) { @@ -218,6 +218,9 @@ export function activate(context: vscode.ExtensionContext) { }, logger: console, on: { + proxyReq: (proxyReq, req, res) => { + console.debug('Proxying an LLM request (to bypass CORS)', { proxyReq, req, res }) + }, proxyRes: (proxyRes, req, res) => { proxyRes.headers['Access-Control-Allow-Origin'] = '*' },