Skip to content

Commit

Permalink
added environment variable for prod vs dev
Browse files Browse the repository at this point in the history
  • Loading branch information
erensunerr committed Mar 21, 2024
1 parent 8945334 commit a54f928
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENV=dev
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "./server/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server/index.js",
"devStart": "nodemon server/index.js"
"start": "node --env-file=.env server/index.js",
"devStart": "nodemon --env-file=.env server/index.js"
},
"keywords": [],
"author": "",
Expand Down
15 changes: 7 additions & 8 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ app.use("/api/comments", comments);

app.use(ErrorHandler);

//uncomment for production
app.use(express.static(path.resolve(__dirname, "../client/dist")));

//Send all non-api requests to the React app.
//uncomment for production
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "../client/dist", "index.html"));
});
if ("ENV" in process.env && process.env.ENV === "prod") {
console.log("!!! RUNNING IN PRODUCTION MODE !!!");
app.use(express.static(path.resolve(__dirname, "../client/dist")));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "../client/dist", "index.html"));
});
}

0 comments on commit a54f928

Please sign in to comment.