From 68a3398f54b0f45bfe8c501c627f531980823ec1 Mon Sep 17 00:00:00 2001 From: Jonas Gloning <34194370+jonasgloning@users.noreply.github.com> Date: Tue, 14 Feb 2023 18:42:21 +0100 Subject: [PATCH] feat: set the PORT with an environment variable Closes #213 --- Dockerfile | 4 ++-- bin/peerjs.ts | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index e83af21..c21cec3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,6 @@ WORKDIR /peer-server COPY package.json package-lock.json ./ RUN npm clean-install --omit=dev COPY --from=build /peer-server/dist/bin/peerjs.js ./ -EXPOSE 9000 +ENV PORT 9000 +EXPOSE ${PORT} ENTRYPOINT ["node", "peerjs.js"] -CMD [ "--port", "9000" ] diff --git a/bin/peerjs.ts b/bin/peerjs.ts index abe718d..bf3f732 100644 --- a/bin/peerjs.ts +++ b/bin/peerjs.ts @@ -11,6 +11,8 @@ import type { AddressInfo } from "node:net"; const y = yargs(hideBin(process.argv)); +const portEnvIsSet = !!process.env["PORT"] + const opts = y .usage("Usage: $0") .wrap(Math.min(optimistUsageLength, y.terminalWidth())) @@ -56,7 +58,7 @@ const opts = y }, port: { type: "number", - demandOption: true, + demandOption: !portEnvIsSet, alias: "p", describe: "port", }, @@ -80,6 +82,9 @@ const opts = y }) .boolean("allow_discovery").parseSync(); +if(!opts.port){ + opts.port= parseInt(process.env["PORT"] as string) +} process.on("uncaughtException", function (e) { console.error("Error: " + e); });