Skip to content

Commit

Permalink
feat: set the PORT with an environment variable
Browse files Browse the repository at this point in the history
Closes #213
  • Loading branch information
jonasgloning committed Feb 14, 2023
1 parent 86cabd8 commit 68a3398
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
7 changes: 6 additions & 1 deletion bin/peerjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -56,7 +58,7 @@ const opts = y
},
port: {
type: "number",
demandOption: true,
demandOption: !portEnvIsSet,
alias: "p",
describe: "port",
},
Expand All @@ -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);
});
Expand Down

0 comments on commit 68a3398

Please sign in to comment.