IngilizAdam
IngilizAdam•11mo ago

proxy-agent not working on Deno Deploy

I'm trying to use a proxy for the node-fetch requests in a deno app. I chose proxy-agent npm package and its working great on my local. It reads HTTP_PROXY environment variable and uses that host as the proxy. But when I deploy my app in Deno Deploy, proxy is not working. I set the environment variable correctly but proxy-agent is just ignoring that? I appreciate any help.
6 Replies
Deno AI Helper
Deno AI Helper•11mo ago
Based on the documentation, Deno Deploy does not currently support all npm packages. While Deno Deploy does support importing built-in Node.js modules, it does not support all npm packages. The proxy-agent package you're trying to use is not a built-in Node.js module, so it might not be supported in Deno Deploy. Deno Deploy does support proxies for module downloads and the Web standard fetch API. Proxy configuration is read from environmental variables: HTTP_PROXY, HTTPS_PROXY and NO_PROXY. However, this is different from using a proxy within your application logic, which seems to be what you're trying to do with proxy-agent. If you're trying to create a proxy server, the documentation provides an example of how to create a basic HTTP proxy server using the fetch API:
import { serve } from "https://deno.land/std/http/mod.ts";
async function reqHandler(req: Request) {
const reqPath = new URL(req.url).pathname;
return await fetch("https://example.com" + reqPath, { headers: req.headers });
}
serve(reqHandler, { port: 8000 });
import { serve } from "https://deno.land/std/http/mod.ts";
async function reqHandler(req: Request) {
const reqPath = new URL(req.url).pathname;
return await fetch("https://example.com" + reqPath, { headers: req.headers });
}
serve(reqHandler, { port: 8000 });
In this example, all requests are proxied to https://example.com. If you're trying to use a proxy for outgoing requests from your application, you might need to use a different approach, as proxy-agent might not be supported in Deno Deploy. Unfortunately, the documentation does not provide a clear answer on how to do this. 🦕
IngilizAdam
IngilizAdam•11mo ago
But proxy-agent is working on my local, so deno supports it. But apparently Deno Deploy doesn't? Isn't it weird that Deno supports it but Deno Deploy service doesn't? Are we sure this is the problem here?
financesaucer
financesaucer•7mo ago
Hi, did you find a way to make it work?
IngilizAdam
IngilizAdam•7mo ago
sadly no it just doesnt work when published but works in local
financesaucer
financesaucer•7mo ago
For me too, even createHttpClient doesnt work because its unstable api and i cant find any other way to make it work... i guess the only way is to self host the sever
IngilizAdam
IngilizAdam•7mo ago
yeah that seems like it