From 5fd23542862e957e21a6119e88ada7902cf2ee14 Mon Sep 17 00:00:00 2001 From: TSR Berry <20988865+TSRBerry@users.noreply.github.com> Date: Wed, 21 Jun 2023 14:40:09 +0200 Subject: [PATCH] Add SOCKET_PATH env var and prefer it over HOST and PORT --- README.md | 1 + src/index.ts | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index aa0dc49..2df24fc 100644 --- a/README.md +++ b/README.md @@ -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]` | diff --git a/src/index.ts b/src/index.ts index d199b50..8a62abf 100755 --- a/src/index.ts +++ b/src/index.ts @@ -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);