feat: support external proxies (#588)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import cors from "cors";
|
||||
import rateLimit from "express-rate-limit";
|
||||
import { setGlobalDispatcher, ProxyAgent } from "undici";
|
||||
|
||||
import { env, version } from "../modules/config.js";
|
||||
|
||||
@@ -208,6 +209,14 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
|
||||
randomizeCiphers();
|
||||
setInterval(randomizeCiphers, 1000 * 60 * 30); // shuffle ciphers every 30 minutes
|
||||
|
||||
if (env.externalProxy) {
|
||||
if (env.freebindCIDR) {
|
||||
throw new Error('Freebind is not available when external proxy is enabled')
|
||||
}
|
||||
|
||||
setGlobalDispatcher(new ProxyAgent(env.externalProxy))
|
||||
}
|
||||
|
||||
app.listen(env.apiPort, env.listenAddress, () => {
|
||||
console.log(`\n` +
|
||||
`${Cyan("cobalt")} API ${Bright(`v.${version}-${gitCommit} (${gitBranch})`)}\n` +
|
||||
|
||||
Reference in New Issue
Block a user