feat: set the PORT with an environment variable

Closes #213
This commit is contained in:
Jonas Gloning 2023-02-14 18:42:21 +01:00
parent 86cabd8bb7
commit 68a3398f54
No known key found for this signature in database
GPG Key ID: 684639B5E59E7614
2 changed files with 8 additions and 3 deletions

View File

@ -13,6 +13,6 @@ WORKDIR /peer-server
COPY package.json package-lock.json ./ COPY package.json package-lock.json ./
RUN npm clean-install --omit=dev RUN npm clean-install --omit=dev
COPY --from=build /peer-server/dist/bin/peerjs.js ./ COPY --from=build /peer-server/dist/bin/peerjs.js ./
EXPOSE 9000 ENV PORT 9000
EXPOSE ${PORT}
ENTRYPOINT ["node", "peerjs.js"] ENTRYPOINT ["node", "peerjs.js"]
CMD [ "--port", "9000" ]

View File

@ -11,6 +11,8 @@ import type { AddressInfo } from "node:net";
const y = yargs(hideBin(process.argv)); const y = yargs(hideBin(process.argv));
const portEnvIsSet = !!process.env["PORT"]
const opts = y const opts = y
.usage("Usage: $0") .usage("Usage: $0")
.wrap(Math.min(optimistUsageLength, y.terminalWidth())) .wrap(Math.min(optimistUsageLength, y.terminalWidth()))
@ -56,7 +58,7 @@ const opts = y
}, },
port: { port: {
type: "number", type: "number",
demandOption: true, demandOption: !portEnvIsSet,
alias: "p", alias: "p",
describe: "port", describe: "port",
}, },
@ -80,6 +82,9 @@ const opts = y
}) })
.boolean("allow_discovery").parseSync(); .boolean("allow_discovery").parseSync();
if(!opts.port){
opts.port= parseInt(process.env["PORT"] as string)
}
process.on("uncaughtException", function (e) { process.on("uncaughtException", function (e) {
console.error("Error: " + e); console.error("Error: " + e);
}); });