PROD mode and backend/.env.example update

This commit is contained in:
Moon Patel
2024-05-13 21:41:20 +05:30
parent 514e7b5fd1
commit 75e4aa3e08
2 changed files with 20 additions and 1 deletions
+5 -1
View File
@@ -15,4 +15,8 @@ PORT=8080
CHESS_ENGINE_PATH=./engine/stockfish16.exe
# hostname
HOSTNAME=http://localhost:8080
HOSTNAME=http://localhost:8080
# can be PROD or DEV
# DEV - development mode
# PROD - same as DEV but serves frontend statics files from ../frontend/dist using the / endpoint
MODE=DEV
+15
View File
@@ -1,3 +1,5 @@
const path = require("path");
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
@@ -8,6 +10,7 @@ const mongoose = require("mongoose");
const cookieParser = require("cookie-parser");
require("dotenv").config();
const MODE = process.env.MODE || "DEV"
const port = process.env.PORT;
mongoose
@@ -45,6 +48,18 @@ app.use("/api/auth", authRoutes);
app.use("/api/user", userRoutes);
app.use("/api/room", roomRoutes);
if (MODE=="PROD") {
console.log('Hello')
app.use(express.static('../frontend/dist'));
app.get("/*", (req,res,next) => {
try {
res.sendFile(path.join(__dirname,"../frontend/dist/index.html"))
} catch(err) {
next(err)
}
})
}
app.use((error, req, res, next) => {
const status = error.status || 500;
console.log(error);