Skip to content

Commit

Permalink
Add NODE_ENV environment variable to Dockerfile and update HOST const…
Browse files Browse the repository at this point in the history
…ant in constants.ts
  • Loading branch information
viperadnan-git committed Feb 1, 2024
1 parent 8ec7df9 commit d814a30
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ FROM node:20

WORKDIR /usr/src/app

ENV NODE_ENV=production

COPY package*.json ./

RUN npm install
Expand Down
2 changes: 1 addition & 1 deletion constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export const CLONE_BOT_BUTTON = {
url: "https://telegra.ph/Create-Your-Own-Lemonic-Bot-A-Step-by-Step-Guide-12-16",
};

export const HOST = process.env.HOST || "0.0.0.0";
export const HOST = process.env.HOST ? process.env.HOST : process.env.NODE_ENV === "production" ? "0.0.0.0" : "localhost";
export const PORT = process.env.PORT ? parseInt(process.env.PORT) : 3000;
7 changes: 4 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ app.all("*", async (req: Request, res: Response) => {
});

app.listen(PORT, HOST, () => {
console.log(`Server listening on http://${HOST}:${PORT}`);

if (!WEBHOOK_URL && !BOT_TOKEN) {
console.error("WEBHOOK_URL or BOT_TOKEN not set");
process.exit(1);
console.warn("WEBHOOK_URL or BOT_TOKEN not set in .env file, new bot cannot be created");
}

if (!WEBHOOK_URL && BOT_TOKEN) {
console.info("Webhook URL not set, starting bot only using polling");
console.info("Webhook URL not set, starting bot using polling");
const bot = botCreator(BOT_TOKEN);
run(bot);
} else if (WEBHOOK_URL && !BOT_TOKEN) {
Expand Down

0 comments on commit d814a30

Please sign in to comment.