-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
54 lines (49 loc) · 1.5 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
45
46
47
48
49
50
51
52
53
54
const express = require("express");
const path = require("path");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const session = require("express-session");
const flash = require("connect-flash");
const app = express();
const cors = require("cors");
require("dotenv").config();
require("./config/dbconnection");
app.use(cors());
app.set("view engine", "ejs");
app.use(
express.urlencoded({
extended: true
})
);
app.use(express.static(path.join(__dirname, "public")));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(
session({
secret: process.env.SECRET_KEY,
resave: false,
saveUninitialized: false
})
);
app.use(flash());
app.use((req, res, next) => {
res.locals.success_msg = req.flash("success_msg");
res.locals.error_msg = req.flash("error_msg");
res.locals.error = req.flash("error");
res.locals.user = req.user || null;
next();
});
app.use("/api/v1/", require("./routes/api/v1/index"));
app.use("/api/v1/users", require("./routes/api/v1/users"));
app.use("/api/v1/resources", require("./routes/api/v1/resources"));
app.use("/api/v1/blogs", require("./routes/api/v1/blogs"));
app.use("/api/v1/contests", require("./routes/api/v1/contests"));
app.use("/api/v1/admin", require("./routes/api/v1/admin"));
app.listen(process.env.PORT, err => {
if (err) {
console.log("Error in running server");
return;
}
console.log(`Server is up and running on PORT ${process.env.PORT}`);
});