mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
feat: support external proxies (#588)
This commit is contained in:
parent
85e376bffd
commit
a6623567e2
3 changed files with 13 additions and 1 deletions
|
@ -56,6 +56,7 @@ 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_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_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_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. |
|
||||||
| `CORS_WILDCARD` | `1` | `0` | toggles cross-origin resource sharing. <br> `0`: disabled. `1`: enabled. |
|
| `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`. |
|
| `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. |
|
| `COOKIE_PATH` | not used | `/cookies.json` | path for cookie file relative to main folder. |
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import rateLimit from "express-rate-limit";
|
import rateLimit from "express-rate-limit";
|
||||||
|
import { setGlobalDispatcher, ProxyAgent } from "undici";
|
||||||
|
|
||||||
import { env, version } from "../modules/config.js";
|
import { env, version } from "../modules/config.js";
|
||||||
|
|
||||||
|
@ -208,6 +209,14 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
|
||||||
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) {
|
||||||
|
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, () => {
|
app.listen(env.apiPort, env.listenAddress, () => {
|
||||||
console.log(`\n` +
|
console.log(`\n` +
|
||||||
`${Cyan("cobalt")} API ${Bright(`v.${version}-${gitCommit} (${gitBranch})`)}\n` +
|
`${Cyan("cobalt")} API ${Bright(`v.${version}-${gitCommit} (${gitBranch})`)}\n` +
|
||||||
|
|
|
@ -48,7 +48,9 @@ const
|
||||||
|
|
||||||
processingPriority: process.platform !== 'win32'
|
processingPriority: process.platform !== 'win32'
|
||||||
&& process.env.PROCESSING_PRIORITY
|
&& process.env.PROCESSING_PRIORITY
|
||||||
&& parseInt(process.env.PROCESSING_PRIORITY)
|
&& parseInt(process.env.PROCESSING_PRIORITY),
|
||||||
|
|
||||||
|
externalProxy: process.env.API_EXTERNAL_PROXY,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const
|
export const
|
||||||
|
|
Loading…
Reference in a new issue