-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (46 loc) · 1.46 KB
/
app.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
46
47
48
49
50
51
52
53
54
55
const express = require("express");
const logger = require("morgan");
const mongoose = require("mongoose");
const path = require("path");
const indexRouter = require("./routes/index");
const userRouter = require("./routes/users");
const adminRouter = require("./routes/admin");
const postRouter = require("./routes/post");
const adPostRouter = require("./routes/ad_post");
const profileRouter = require("./routes/profile");
const carouselRouter = require("./routes/carousel");
// Import dotenv
require("dotenv").config();
var app = express();
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static("public"));
//Set static folder
app.use(express.static("client/build"));
// Connect mongoose
mongoose.connect(
process.env.MONGOURL,
{ useNewUrlParser: true, useUnifiedTopology: true },
err => {
if (err) {
console.log(err);
} else {
require("./utils/seed.js");
console.log("success mongodb connected");
}
}
);
mongoose.set("useCreateIndex", true);
mongoose.set("useFindAndModify", false);
app.use("/api/timeline", indexRouter);
app.use("/api/users", userRouter);
app.use("/api/admin", adminRouter);
app.use("/api/post", postRouter);
app.use("/api/adpost", adPostRouter);
app.use("/api/profile", profileRouter);
app.use("/api/carousel", carouselRouter);
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
module.exports = app;