-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (24 loc) · 878 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const express = require('express')
const mongoose = require('mongoose')
const cookieParser = require("cookie-parser")
require('dotenv').config();
const app = express();
const PORT = process.env.PORT || 5000;
mongoose.connect(process.env.MONGODB_URL,{
useNewUrlParser:true,
useCreateIndex:true,
useFindAndModify:false,
useUnifiedTopology:true
}).then(() => console.log("DB connected successfully")).catch((err) => console.log(err))
app.use(express.json());
app.use(cookieParser());
const authRoute = require("./routes/auth")
app.use(authRoute);
if ( process.env.NODE_ENV === "production"){
app.use(express.static("frontend/build"));
const path = require("path");
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, 'frontend', 'build', 'index.html'));
})
}
app.listen(PORT,() => console.log(`PORT running at ${PORT}`))