diff --git a/extensions/vscode/src/activation/proxy.ts b/extensions/vscode/src/activation/proxy.ts index a002e4373..c181a16fa 100644 --- a/extensions/vscode/src/activation/proxy.ts +++ b/extensions/vscode/src/activation/proxy.ts @@ -1,33 +1,50 @@ import cors from "cors"; import express from "express"; -import { createProxyMiddleware } from "http-proxy-middleware"; +import http from "http"; const PROXY_PORT = 65433; const app = express(); app.use(cors()); -app.use("/", (req, res, next) => { - // Extract the target from the request URL - // const { protocol, host } = url.parse(req.url); - // const target = `${protocol}//${host}`; - const target = "http://localhost:11434"; - - // Create a new proxy middleware for this request - const proxy = createProxyMiddleware({ - target, - changeOrigin: true, - ws: true, - pathRewrite: { - "^/": "/api/generate", +app.use((req, res, next) => { + // Proxy the request + const { origin, ...headers } = req.headers; + const proxy = http.request( + req.headers["x-continue-url"] as string, + { + method: req.method, + headers: headers, }, - }); + (response) => { + // Pipe the response stream directly to the client + response.pipe(res); + } + ); - // Call the middleware - proxy(req, res, next); + // Pipe the request stream directly to the proxy + req.pipe(proxy); }); +// http-middleware-proxy +// app.use("/", (req, res, next) => { +// // Extract the target from the request URL +// const target = req.headers["x-continue-url"] as string; +// const { origin, ...headers } = req.headers; + +// // Create a new proxy middleware for this request +// const proxy = createProxyMiddleware({ +// target, +// ws: true, +// headers: { +// origin: "", +// }, +// }); + +// // Call the middleware +// proxy(req, res, next); +// }); + export function startProxy() { - console.log("Starting proxy"); app.listen(PROXY_PORT, () => { console.log(`Proxy server is running on port ${PROXY_PORT}`); });