mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-27 07:38:28 +00:00
api/core: use EnvHttpProxyAgent for proxy requests
This commit is contained in:
parent
95efd71eac
commit
e83baa9138
@ -1,7 +1,7 @@
|
|||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import http from "node:http";
|
import http from "node:http";
|
||||||
import rateLimit from "express-rate-limit";
|
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 { getCommit, getBranch, getRemote, getVersion } from "@imput/version-info";
|
||||||
|
|
||||||
import jwt from "../security/jwt.js";
|
import jwt from "../security/jwt.js";
|
||||||
@ -337,9 +337,10 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
|
|||||||
randomizeCiphers();
|
randomizeCiphers();
|
||||||
setInterval(randomizeCiphers, 1000 * 60 * 30); // shuffle ciphers every 30 minutes
|
setInterval(randomizeCiphers, 1000 * 60 * 30); // shuffle ciphers every 30 minutes
|
||||||
|
|
||||||
if (env.externalProxy) {
|
// TODO: remove env.externalProxy in a future version
|
||||||
setGlobalDispatcher(new ProxyAgent(env.externalProxy))
|
setGlobalDispatcher(
|
||||||
}
|
new EnvHttpProxyAgent({ httpProxy: env.externalProxy || undefined })
|
||||||
|
);
|
||||||
|
|
||||||
http.createServer(app).listen({
|
http.createServer(app).listen({
|
||||||
port: env.apiPort,
|
port: env.apiPort,
|
||||||
|
@ -4,7 +4,7 @@ import { env } from "../config.js";
|
|||||||
import { runTest } from "../misc/run-test.js";
|
import { runTest } from "../misc/run-test.js";
|
||||||
import { loadJSON } from "../misc/load-from-fs.js";
|
import { loadJSON } from "../misc/load-from-fs.js";
|
||||||
import { Red, Bright } from "../misc/console-text.js";
|
import { Red, Bright } from "../misc/console-text.js";
|
||||||
import { setGlobalDispatcher, ProxyAgent } from "undici";
|
import { setGlobalDispatcher, EnvHttpProxyAgent, ProxyAgent } from "undici";
|
||||||
import { randomizeCiphers } from "../misc/randomize-ciphers.js";
|
import { randomizeCiphers } from "../misc/randomize-ciphers.js";
|
||||||
|
|
||||||
import { services } from "../processing/service-config.js";
|
import { services } from "../processing/service-config.js";
|
||||||
@ -69,9 +69,10 @@ const printHeader = (service, padLen) => {
|
|||||||
console.log(service + '='.repeat(50));
|
console.log(service + '='.repeat(50));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env.externalProxy) {
|
// TODO: remove env.externalProxy in a future version
|
||||||
setGlobalDispatcher(new ProxyAgent(env.externalProxy));
|
setGlobalDispatcher(
|
||||||
}
|
new EnvHttpProxyAgent({ httpProxy: env.externalProxy || undefined })
|
||||||
|
);
|
||||||
|
|
||||||
env.streamLifespan = 10000;
|
env.streamLifespan = 10000;
|
||||||
env.apiURL = 'http://x/';
|
env.apiURL = 'http://x/';
|
||||||
|
@ -124,7 +124,7 @@ defines the local address for the api instance. if you are using a docker contai
|
|||||||
the value is a local IP address.
|
the value is a local IP address.
|
||||||
|
|
||||||
### API_EXTERNAL_PROXY
|
### API_EXTERNAL_PROXY
|
||||||
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.
|
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.
|
||||||
|
|
||||||
if some feature breaks when using a proxy, please make a new issue about it!
|
if some feature breaks when using a proxy, please make a new issue about it!
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user