PROD mode and backend/.env.example update
This commit is contained in:
@@ -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
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user