Closed ojoggerst closed 2 weeks ago
I need this feature to be able to use smee in our environment. Would love to see it become reality ❤️
You can pass in your own custom fetch wrapper. NodeJS doesn't support Proxies out of the box with the Fetch API currently
import { fetch as undiciFetch, ProxyAgent } from 'undici';
import SmeeClient from "smee-client";
const myFetch = (url, options) => {
return undiciFetch(url, {
...options,
dispatcher: new ProxyAgent(<your_proxy_url>)
})
}
const smee = new SmeeClient({
source: 'https://smee.io/abc123',
target: 'http://localhost:3000/events',
logger: console,
fetch: myFetch
})
This should be added to the README
where are we meant to pass the custom fetch wrapper to? smee.js?
i tried the previous solution and ended up with a sea of errors.
where are we meant to pass the custom fetch wrapper to? smee.js?
Yes. That is what is indicated in the code example I shared
i tried the previous solution and ended up with a sea of errors.
Those packages are probably not compatible with the native Fetch API available in Node and instead use the Node HTTP API
Actually the examply is not quite the recommended way by undici.
You would use setGlobalDispatcher to set the proxy agent globally. Also there is EnvProxyAgent, which can handle the HTTP_PROXY and HTTPS_PROXY env variables. I have to look up if it is enabled by default now on node.js, but that was the desired behavior.
Actually the examply is not quite the recommended way by undici.
You would use setGlobalDispatcher to set the proxy agent globally. Also there is EnvProxyAgent, which can handle the HTTP_PROXY and HTTPS_PROXY env variables. I have to look up if it is enabled by default now on node.js, but that was the desired behavior.
Undici probably updated since then, but my solution is backwards compatible to all NodeJS versions we support.
At the time of Node 18.0, there was no support for the HTTP_PROXY
and HTTPS_PROXY
env variables, nor was there an EnvProxyAgent
Besides, do we really want to include undici (which is a fairly large package) just to be able to have the proxy env variables?
even having tried your solution @wolfy1339, i am still receiving connection timeouts. this has been hindering me for a few days now
What version are you running?
node is 18.20.2, smee is 2.0.2
There is also another place you need to specify the proxy: https://www.npmjs.com/package/eventsource#httphttps-proxy
npmW3C compliant EventSource client for Node.js and browser (polyfill). Latest version: 2.0.2, last published: 2 years ago. Start using eventsource in your project by running `npm i eventsource`. There are 805 other projects in the npm registry using eventsource.
:tada: This issue has been resolved in version 3.0.0-beta.2 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
:tada: This issue has been resolved in version 2.0.4 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Problem description
We would like to use the smee client behind a proxy. Currently, there is no possibility to add a proxy URL to the smee client, so that all outgoing connections would be proxied through a specific server.
Solution
Option one needs code changes and seems a bit more cumbersome.
Option two is fairly simple and only needs global agent dependencies and one line in index.js to import the package.
After that you can do:
GLOBAL_AGENT_HTTP_PROXY=http://<proxy-host>:<proxy-port> node ./bin/smee.js -u https://<smee-server>/<token>
Please check PR: https://github.com/probot/smee-client/pull/195