-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
83 lines (54 loc) · 1.93 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const express = require('express');
const app = express();
const apiErrorHandler = require('./middleware/ApiErrorHandler/api-error-handler');
const morgan = require('morgan');
const path = require('path');
require('dotenv').config();
const ejs = require('ejs');
const expressLayouts = require('express-ejs-layouts')
const mongoose = require("mongoose");
const port = process.env.PORT || 3000;
const cookieParser = require('cookie-parser');
const session = require('express-session');
const connectFlash = require('connect-flash');
const db = require("./config/mongoDb");
mongoose.set('bufferCommands', false);
const indexRouter = require("./routes/indexRoutes");
const userRouter = require("./routes/userRoutes");
const adminRouter = require("./routes/adminRoutes");
global.globalString = "This can be accessed anywhere!";
console.log(globalString);
app.use(cookieParser());
app.use(morgan("dev"));
app.use(session({ secret: 'someKeysPrefer', saveUninitialized: true, resave: false, cookie: { maxAge: 60000 * 60 } }));
app.use(connectFlash());
app.use(express.static(path.join(__dirname, "public")));
app.use(expressLayouts);
app.set('layout', 'layouts/layout');
app.set("view engine", "ejs");
console.log(__dirname);
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(apiErrorHandler);
app.use((req, res, next) => {
console.log("req.path: " + req.path, " req.method: " + req.method, " req.url: " + req.url, " req.href: " + req.href);
console.log(req.body);
console.log(req.query)
console.log(req.params);
next();
})
app.use('/public', (req, res, next) => {
const { url, path: routePath } = req;
console.log(url);
next();
});
app.use((req, res, next) => {
res.set('cache-control', 'no-store')
next()
})
app.use("/", indexRouter);
app.use("/user", userRouter);
app.use("/admin", adminRouter);
app.listen(port, () => {
console.log("Server Started at " + port)
})