Add SOCKET_PATH env var and prefer it over HOST and PORT

This commit is contained in:
TSR Berry 2023-06-21 14:40:09 +02:00
parent 65b14e7c8a
commit 5fd2354286
No known key found for this signature in database
GPG key ID: 52353C0A4CCA15E2
2 changed files with 8 additions and 1 deletions

View file

@ -23,6 +23,7 @@ This app can be configured using the following environment variables:
| Name | Description | Default value | Notes |
| :------------- | ----------------------------------------------------------------------------------------- | :-----------: | ---------------------------------------------------------------------- |
| `NODE_ENV` | This should be set to `production` or `development` depending on the current environment. | `""` | |
| `SOCKET_PATH` | The path to the unix socket this server should be listening on. | `""` | If this is not empty `HOST` and `PORT` will be ignored. |
| `HOST` | The address this server should be listening on. | `"127.0.0.1"` | |
| `PORT` | The port this server should be using. | `3000` | |
| `REDIS_URL` | The URL of the redis server. | `""` | Format: `redis[s]://[[username][:password]@][host][:port][/db-number]` |

View file

@ -3,7 +3,13 @@ import { app, logger } from "./app";
import http from "http";
const server = http.createServer(app);
server.listen(parseInt(env.PORT || "3000"), env.HOST || "127.0.0.1");
if (process.env.SOCKET_PATH != null && process.env.SOCKET_PATH.length > 0) {
server.listen(process.env.SOCKET_PATH);
}
else {
server.listen(parseInt(env.PORT || "3000"), env.HOST || "127.0.0.1");
}
server.on("error", (error: Error) => {
logger.error("An error occurred.", error);