-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (33 loc) · 1.13 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
42
43
44
const express = require("express");
const config = require("./server/congif");
const bodyParser = require("body-parser");
const cors = require("cors");
const helmet = require("helmet");
const mongoose = require("mongoose");
const commentRoutes = require("./server/routes/comment.routes");
const postRoutes = require("./server/routes/post.routes");
const path = require("path");
const app = express();
app.use(express.static(path.join(__dirname, "client/build")));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(helmet());
app.use(cors());
//mounting the routes
app.use("/", commentRoutes);
app.use("/", postRoutes);
// connect to the database
mongoose.connect(
config.mongoUri, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log(`Database connected successfully`))
.catch((err) => console.log(err));
mongoose.Promise = global.Promise;
app.get("/", function (req, res) {
res.sendFile(path.join(__dirname + "./client/build/index.html"));
});
app.listen(config.serverPort, () => {
console.log(`Example app listening at http://localhost:${config.serverPort}`);
});