Skip to content

Commit

Permalink
feat: allow port to be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
Inlustra committed Jun 30, 2021
1 parent c16a93d commit 864dc19
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 14 additions & 6 deletions server/environment.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
export const environment = () => ({
loggingLevel: process.env.LOGGER_LEVEL ?? "info",
localConfigFile:
process.env.DOCKER_DASH_LOCAL_CONFIG_FILE ??
process.env.NODE_ENV === "production"
? "/config.json"
: "./config.json",
get port() {
const envVar = process.env.DOCKER_DASH_PORT;
if (envVar) {
try {
return parseInt(envVar, 10);
} catch (error) {
console.error("[environment] Error getting port", error);
}
}
return 3000;
},
dev: process.env.NODE_ENV !== "production",
loggingLevel: process.env.DOCKER_DASH_LOGGER_LEVEL ?? "info",
localConfigFile: process.env.DOCKER_DASH_LOCAL_CONFIG_FILE ?? "/config.json",
});

export type Environment = ReturnType<typeof environment>;
3 changes: 1 addition & 2 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { environment } from "./environment";
import { agent } from "./agent";
import { ReplaySubject } from "rxjs";

const port = parseInt(process.env.PORT || "3000", 10);
const dev = process.env.NODE_ENV !== "production";
const { port, dev } = environment();

async function tryQuietly(fn: () => any | Promise<any>) {
return async () => {
Expand Down

0 comments on commit 864dc19

Please sign in to comment.