From 37cf726e4926640da158ee67d86a1937b2c89c68 Mon Sep 17 00:00:00 2001 From: Francesco Piccoli <70111810+francescoopiccoli@users.noreply.github.com> Date: Mon, 13 Jan 2025 16:08:56 +0100 Subject: [PATCH] fix: make proxy nodejs only (#716) Co-authored-by: Francesco Piccoli --- .../streamingClient/codewhispererStreamingClient.ts | 10 ++++++++-- .../src/language-server/proxy-server.ts | 11 ++++++++--- .../src/language-server/utils.ts | 10 ++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/server/aws-lsp-codewhisperer/src/client/streamingClient/codewhispererStreamingClient.ts b/server/aws-lsp-codewhisperer/src/client/streamingClient/codewhispererStreamingClient.ts index 2110651b..3f555c32 100644 --- a/server/aws-lsp-codewhisperer/src/client/streamingClient/codewhispererStreamingClient.ts +++ b/server/aws-lsp-codewhisperer/src/client/streamingClient/codewhispererStreamingClient.ts @@ -17,8 +17,14 @@ export async function createStreamingClient( const creds = credentialsProvider.getCredentials('bearer') let clientOptions - const proxyUrl = process.env.HTTPS_PROXY ?? process.env.https_proxy - const certs = process.env.AWS_CA_BUNDLE ? [readFileSync(process.env.AWS_CA_BUNDLE)] : undefined + // short term solution to fix webworker bundling, broken due to this node.js specific logic in here + const isNodeJS: boolean = typeof process !== 'undefined' && process.release && process.release.name === 'node' + const proxyUrl = isNodeJS ? (process.env.HTTPS_PROXY ?? process.env.https_proxy) : undefined + const certs = isNodeJS + ? process.env.AWS_CA_BUNDLE + ? [readFileSync(process.env.AWS_CA_BUNDLE)] + : undefined + : undefined if (proxyUrl) { const agent = new HttpsProxyAgent({ diff --git a/server/aws-lsp-codewhisperer/src/language-server/proxy-server.ts b/server/aws-lsp-codewhisperer/src/language-server/proxy-server.ts index c11ec53d..6d4ba4c3 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/proxy-server.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/proxy-server.ts @@ -28,9 +28,14 @@ export const QNetTransformServerTokenProxy = QNetTransformServerToken((credentia export const QChatServerProxy = QChatServer(credentialsProvider => { let clientOptions: ChatSessionServiceConfig | undefined - - const proxyUrl = process.env.HTTPS_PROXY ?? process.env.https_proxy - const certs = process.env.AWS_CA_BUNDLE ? [readFileSync(process.env.AWS_CA_BUNDLE)] : undefined + // short term solution to fix webworker bundling, broken due to this node.js specific logic in here + const isNodeJS: boolean = typeof process !== 'undefined' && process.release && process.release.name === 'node' + const proxyUrl = isNodeJS ? (process.env.HTTPS_PROXY ?? process.env.https_proxy) : undefined + const certs = isNodeJS + ? process.env.AWS_CA_BUNDLE + ? [readFileSync(process.env.AWS_CA_BUNDLE)] + : undefined + : undefined if (proxyUrl) { clientOptions = () => { diff --git a/server/aws-lsp-codewhisperer/src/language-server/utils.ts b/server/aws-lsp-codewhisperer/src/language-server/utils.ts index aa75ed42..03cbf950 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/utils.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/utils.ts @@ -133,10 +133,16 @@ export function getEndPositionForAcceptedSuggestion(content: string, startPositi export const makeProxyConfig = async (workspace: Workspace) => { let additionalAwsConfig: ConfigurationOptions = {} - const proxyUrl = process.env.HTTPS_PROXY ?? process.env.https_proxy + // short term solution to fix webworker bundling, broken due to this node.js specific logic in here + const isNodeJS: boolean = typeof process !== 'undefined' && process.release && process.release.name === 'node' + const proxyUrl = isNodeJS ? (process.env.HTTPS_PROXY ?? process.env.https_proxy) : undefined if (proxyUrl) { - const certs = process.env.AWS_CA_BUNDLE ? [await workspace.fs.readFile(process.env.AWS_CA_BUNDLE)] : undefined + const certs = isNodeJS + ? process.env.AWS_CA_BUNDLE + ? [await workspace.fs.readFile(process.env.AWS_CA_BUNDLE)] + : undefined + : undefined const agent = new HttpsProxyAgent({ proxy: proxyUrl, ca: certs,