-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
45 lines (38 loc) · 1.16 KB
/
server.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
42
43
44
45
require("dotenv").config();
const express = require("express");
const db = require("./config/db_config");
const path = require("path");
const cookieParser = require("cookie-parser");
// Routers
const home = require("./routes/home");
const auth = require("./routes/auth");
const profile = require("./routes/profile");
const scrap = require("./routes/scrap");
const search = require("./routes/search");
const friends = require("./routes/friends");
// PORT
const PORT = process.env.PORT || 5000;
// App
const app = express();
//MiddleWares
app.use(express.json());
app.use(cookieParser());
app.use("/public", express.static(path.resolve(__dirname, "./public")));
app.use(express.static(path.resolve(__dirname, "./client/build")));
// Routes
app.use("/", home);
app.use("/profile", profile);
app.use("/auth", auth);
app.use("/search", search);
app.use("/scrap", scrap);
app.use("/friends", friends);
if (process.env.NODE_ENV === "production") {
// Basename is client should be '/app'
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
// Listen
app.listen(PORT, () => {
console.log("Server is up and running!");
});