-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (33 loc) · 1.08 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const authRoute = require("./routes/auth");
const userRoute = require("./routes/users");
const cors = require("cors");
const path = require("path");
const verify = require("./verifyToken");
dotenv.config();
mongoose
.connect(process.env.MONGO_URL)
.then(() => console.log("DB connection success..."))
.catch((err) => console.log(err));
app.use(express.json());
const corsOptions = {
origin: "*",
credentials: true, // Access-control-allow-credentials:true
optionSuccessStatus: 200,
};
app.use(cors(corsOptions)); // Use this after the variable declaration
app.use("/api/auth", authRoute);
app.use("/api/users", verify, userRoute);
// Deloy
if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, "/client/build")));
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "/client/build", "index.html"));
});
}
app.listen(process.env.PORT || 8800, () => {
console.log("Backend server is running...");
});