-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
50 lines (38 loc) · 1.12 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
import dotenv from "dotenv";
dotenv.config();
import express from "express";
import expressLayout from "express-ejs-layouts";
import methodOverride from "method-override";
import cookieParser from "cookie-parser";
import session from "express-session";
import MongoStore from "connect-mongo";
import connectDB from "./server/config/db.js";
import mainRoutes from "./server/routers/main.js";
import adminRoutes from "./server/routers/admin.js";
const app = express();
const PORT = process.env.PORT || 5096;
app.use(express.urlencoded({ extended: true }));
app.set("view engine", "ejs");
app.use(express.json());
app.use(cookieParser());
app.use(
session({
secret: "keyboard cat",
resave: false,
saveUninitialized: true,
store: MongoStore.create({
mongoUrl: process.env.MONGODB_URI,
}),
})
);
app.use(methodOverride("_method"));
app.use(express.static("public"));
app.use(express.static("uploads"));
app.use(expressLayout);
connectDB();
app.set("layout", "./layouts/main");
app.use("/", mainRoutes);
app.use("/", adminRoutes);
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
});