From cc1e9dcff88990dde35ff81c256f5d8608fd301d Mon Sep 17 00:00:00 2001 From: dumbmoron Date: Mon, 13 May 2024 18:20:10 +0000 Subject: [PATCH] api: add API_LISTEN_ADDRESS env for specifying bind address --- docs/run-an-instance.md | 1 + src/core/api.js | 2 +- src/modules/config.js | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/run-an-instance.md b/docs/run-an-instance.md index 9e607942..d89d506c 100644 --- a/docs/run-an-instance.md +++ b/docs/run-an-instance.md @@ -53,6 +53,7 @@ sudo service nscd start | variable name | default | example | description | |:----------------------|:----------|:------------------------|:------------| | `API_PORT` | `9000` | `9000` | changes port from which api server is accessible. | +| `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://co.wuk.sh/` | changes url from which api server is accessible.
***REQUIRED TO RUN API***. | | `API_NAME` | `unknown` | `ams-1` | api server name that is shown in `/api/serverInfo`. | | `CORS_WILDCARD` | `1` | `0` | toggles cross-origin resource sharing.
`0`: disabled. `1`: enabled. | diff --git a/src/core/api.js b/src/core/api.js index 440c25c2..31ed7dd5 100644 --- a/src/core/api.js +++ b/src/core/api.js @@ -194,7 +194,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) { res.redirect('/api/json') }); - app.listen(env.apiPort, () => { + app.listen(env.apiPort, env.listenAddress, () => { console.log(`\n` + `${Cyan("cobalt")} API ${Bright(`v.${version}-${gitCommit} (${gitBranch})`)}\n` + `Start time: ${Bright(`${startTime.toUTCString()} (${startTimestamp})`)}\n\n` + diff --git a/src/modules/config.js b/src/modules/config.js index 93347ad4..89ac1b33 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -29,6 +29,7 @@ const apiEnvs = { apiPort: process.env.API_PORT || 9000, apiName: process.env.API_NAME || 'unknown', + listenAddress: process.env.API_LISTEN_ADDRESS, corsWildcard: process.env.CORS_WILDCARD !== '0', corsURL: process.env.CORS_URL, cookiePath: process.env.COOKIE_PATH,