-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (34 loc) · 1.17 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
const express = require("express");
const app = express();
const path = require("path");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
dotenv.config();
const port = process.env.PORT || 5500;
//Import routes
mongoose.set("useFindAndModify", false);
mongoose.connect(
process.env.DB_LINK,
{ useNewUrlParser: true },
() => console.log("DB connected")
);
const handleUsers = require("./routes/handleUsers");
const handleProducts = require("./routes/handleProducts");
const addNewProduct = require("./routes/addNewProduct");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use("/images", express.static("images"));
app.use(express.static(path.join(__dirname, "client/build")));
// app.use(express.static(path.join(__dirname, "public")));
app.use("/", handleProducts);
app.use("/user", handleUsers);
app.use("/", addNewProduct);
app.get("/*", function(req, res) {
res.sendFile(path.join(__dirname, "client/build/index.html"), function(err) {
if (err) {
res.status(500).send(err);
}
});
});
app.listen(port, () => console.log(`Server started on port ${port}`));