Commit 7d2be0f
authored
feat: Replace
Hello 👋
Here is a PR proposition to be able to use `apify` CLI in a sandboxed
environment (in my case, Claude code in the browser).
At the moment, we can't do `apify login` or `apify info` in such
environment, because the **apify-client** doesn't handle the proxy
configuration properly.
The commands are stuck.
Digging into it, I found out that the `agentkeepalive` module doesn't
support proxy (see
node-modules/agentkeepalive#22 (comment)
for instance).
I first attempted to use
[proxy-agents](https://github.com/TooTallNate/proxy-agents), but it
turns out the built-in agents can support both keepalive and proxies out
of the box.
So this PR removes `agentkeepalive` while maintaining the same
keep-alive functionality and adding proxy support capability.
### Test
To test it locally, I created a transparent proxy (we don't intercept
requests to avoid self-certificate issues):
```sh
mitmdump --listen-port 8000 --ignore-hosts '.*:*' --set dns_log=true
```
And in another terminal, I tested the Apify client with :
```sh
export HTTPS_PROXY=http://localhost:8000
export APIFY_TOKEN=[REPLACE_WITH_VALID_TOKEN]
node get-user-info.js # See code below
```
```js
#!/usr/bin/env node
const { ApifyClient } = require('./dist/index.js');
async function main() {
// Get token from environment variable
const token = process.env.APIFY_TOKEN;
if (!token) {
console.error('Error: APIFY_TOKEN environment variable is not set');
process.exit(1);
}
try {
const client = new ApifyClient({ token });
console.log('Fetching user information...\n');
const userInfo = await client.user().get();
console.log('User Information:');
console.log(JSON.stringify(userInfo, null, 2));
} catch (error) {
console.error('Error fetching user information:');
console.error(error.message);
if (error.statusCode) {
console.error(`Status Code: ${error.statusCode}`);
}
process.exit(1);
}
}
main();
```agentkeepalive with native Node.js HTTP agents for proxy support (#788)1 parent 5860629 commit 7d2be0f
File tree
4 files changed
+36
-34
lines changed- src
4 files changed
+36
-34
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | | - | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | | - | |
| 36 | + | |
36 | 37 | | |
37 | | - | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
62 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
63 | 75 | | |
64 | | - | |
65 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
66 | 88 | | |
67 | 89 | | |
68 | 90 | | |
| |||
0 commit comments