-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
41 lines (33 loc) · 895 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
31
32
33
34
35
36
37
38
39
40
41
// Dependencies
const express = require("express"),
app = express(),
cors = require("cors"),
path = require("path"),
cookieParser = require("cookie-parser");
const passport = require("./middlewares/passport");
// Import routes
let routes = require("./routes");
// Configure .env file
require("dotenv").config();
// Connecting to database
require("./models/connect")();
// Middleware function
app.use(cors());
app.use(cookieParser());
app.use(express.json());
app.use(passport.initialize());
// Routes
app.use("/api", routes);
if (
process.env.NODE_ENV === "production" ||
process.env.NODE_ENV === "staging"
) {
app.use(express.static("client/build"));
app.get("*", (_, res) => {
res.sendFile(path.join(__dirname + "/client/build/index.html"));
});
}
// Activate the server
app.listen(process.env.PORT, () => {
console.log(`Listening at ${process.env.PORT}`);
});