-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
50 lines (43 loc) · 1.53 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
const express = require("express");
const session = require("express-session");
const config = require("config");
const debug = require("debug")("app:debug");
const bodyPrser = require("body-parser");
const db = require("./database/db");
const postApi = require("./route/api/postApi");
const communityApi = require("./route/api/communityApi");
const homeRoutes = require("./route/homeRounts");
const userRoutes = require("./route/usersRoutes");
const postRoutes = require("./route/postRoutes");
const communityRoutes = require("./route/communityRoutes");
const settingRoutes = require("./route/settingsRoutes")
const searchRoutes = require("./route/searchRoutes")
const { json } = require("express/lib/response");
const app = express();
debug(app.get("env"));
const port = config.get("PORT");
app.use(express.static("public"));
app.use(express.static("node_modules"));
app.use(express.json());
app.use(bodyPrser.urlencoded({ extended: false }));
app.use(session({
secret: "SESSION_SECRECT",
resave: true,
saveUninitialized: false
}));
app.use(function (req, res, next) {
res.locals.session = req.session.user;
next();
});
app.set("view engine", "pug");
app.set("views", "views");
app.use("/api/posts", postApi);
app.use("/api/communities", communityApi);
app.use("/", homeRoutes);
app.use("/users", userRoutes)
app.use("/posts", postRoutes)
app.use("/communities", communityRoutes)
app.use("/settings", settingRoutes)
app.use("/search", searchRoutes)
db();
const server = app.listen(port, () => console.log(`Start server on port ${port}`));