api/core: use EnvHttpProxyAgent for proxy requests

This commit is contained in:
hyperdefined 2025-03-26 14:11:24 -04:00
parent 2d38d63003
commit fdfda6e8f7
No known key found for this signature in database
GPG Key ID: 73E2F183DF9477C6
4 changed files with 7 additions and 6 deletions

View File

@ -36,7 +36,7 @@
"ipaddr.js": "2.2.0",
"nanoid": "^5.0.9",
"set-cookie-parser": "2.6.0",
"undici": "^5.19.1",
"undici": "^7.5.0",
"url-pattern": "1.0.3",
"youtubei.js": "^13.3.0",
"zod": "^3.23.8"

View File

@ -1,7 +1,7 @@
import cors from "cors";
import http from "node:http";
import rateLimit from "express-rate-limit";
import { setGlobalDispatcher, ProxyAgent } from "undici";
import { setGlobalDispatcher, EnvHttpProxyAgent } from "undici";
import { getCommit, getBranch, getRemote, getVersion } from "@imput/version-info";
import jwt from "../security/jwt.js";
@ -346,7 +346,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
throw new Error('Freebind is not available when external proxy is enabled')
}
setGlobalDispatcher(new ProxyAgent(env.externalProxy))
setGlobalDispatcher(new EnvHttpProxyAgent(env.externalProxy))
}
http.createServer(app).listen({

View File

@ -4,7 +4,7 @@ import { env } from "../config.js";
import { runTest } from "../misc/run-test.js";
import { loadJSON } from "../misc/load-from-fs.js";
import { Red, Bright } from "../misc/console-text.js";
import { setGlobalDispatcher, ProxyAgent } from "undici";
import { setGlobalDispatcher, EnvHttpProxyAgent } from "undici";
import { randomizeCiphers } from "../misc/randomize-ciphers.js";
import { services } from "../processing/service-config.js";
@ -70,7 +70,7 @@ const printHeader = (service, padLen) => {
}
if (env.externalProxy) {
setGlobalDispatcher(new ProxyAgent(env.externalProxy));
setGlobalDispatcher(new EnvHttpProxyAgent(env.externalProxy));
}
env.streamLifespan = 10000;

View File

@ -61,7 +61,8 @@ sudo service nscd start
| `API_LISTEN_ADDRESS` | `0.0.0.0` | `127.0.0.1` | changes address from which api server is accessible. **if you are using docker, you usually don't need to configure this.** |
| `API_URL` | | `https://api.cobalt.tools/` | changes url from which api server is accessible. <br> ***REQUIRED TO RUN THE API***. |
| `API_NAME` | `unknown` | `ams-1` | api server name that is shown in `/api/serverInfo`. |
| `API_EXTERNAL_PROXY` | | `http://user:password@127.0.0.1:8080`| url of the proxy that will be passed to [`ProxyAgent`](https://undici.nodejs.org/#/docs/api/ProxyAgent) and used for all external requests. HTTP(S) only. |
| `API_EXTERNAL_PROXY` | | `http://user:password@127.0.0.1:8080`| url of the proxy that will be passed to [`EnvHttpProxyAgent`](https://undici.nodejs.org/#/docs/api/EnvHttpProxyAgent) and used for all external requests. HTTP(S) only. |
| `NO_PROXY` | | `127.0.0.1` | comma separated list of IPs that will not be proxied. |
| `CORS_WILDCARD` | `1` | `0` | toggles cross-origin resource sharing. <br> `0`: disabled. `1`: enabled. |
| `CORS_URL` | not used | `https://cobalt.tools` | cross-origin resource sharing url. api will be available only from this url if `CORS_WILDCARD` is set to `0`. |
| `COOKIE_PATH` | not used | `/cookies.json` | path for cookie file relative to main folder. |