-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
114 lines (93 loc) · 3.21 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const express = require("express");
require("./db/mongoose");
const path = require("path");
//packages
const passport = require("passport");
const flash = require("connect-flash");
const session = require("express-session");
var bodyParser = require("body-parser");
const hbs = require("hbs");
const ejs = require("ejs");
var compression = require("compression");
//models
const mongoose = require("mongoose");
const Form = require("./models/form");
//Rroutes
const formRouter = require("./routers/form/formRouter");
const studentRouter = require("./routers/student/studentRouter");
//subadmin routes
const subadminRouter = require("./routers/subadmin/subadminRouter");
const authorityUserRequestsRouter = require("./routers/subadmin/authorityUserRequests/authorityUserRequestsRouter");
const eventRequestsRouter = require("./routers/subadmin/eventRequests/eventRequestsRouter");
const leaveApplicationsRouter = require("./routers/subadmin/leaveApplications/leaveApplicationsRouter");
//admin routes
const adminRouter = require("./routers/admin/adminRouter");
const excelsheet = require("./routers/admin/excelsheet");
const reportsheet = require("./routers/admin/report/reportexcel");
const subadminRequestsRouter = require("./routers/admin/subadminRequests/subadminRequestsRouter");
const userAuthRequestsRouter = require("./routers/admin/userAuthRequests/userAuthRequestsRouter");
const app = express();
const port = process.env.PORT;
// Passport Config
require("./config/passport")(passport);
// setting directory paths
const publicDirectoryPath = path.join(__dirname, "./public");
const viewsPath = path.join(__dirname, "./templates/views/");
// setting viewsPath ejs hbs
app.set("view engine", "hbs");
app.set("view engine", "ejs");
app.set("views", viewsPath);
app.use(express.static(publicDirectoryPath));
//use compression
app.use(compression());
//body parser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.json());
// Express session
app.use(
session({
secret: "secret",
resave: true,
saveUninitialized: true,
})
);
// Passport middleware
app.use(passport.initialize());
app.use(passport.session());
// Connect flash
app.use(flash());
// Global variables
app.use(function (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");
next();
});
global.__basedir = __dirname;
console.log(__basedir);
// Routes
app.use("/", require("./routers/index.js"));
app.use("/loginActivity", require("./routers/LoginActivity.js"));
app.use(formRouter);
app.use(studentRouter);
app.use(adminRouter);
app.use(excelsheet);
app.use(reportsheet);
app.use(userAuthRequestsRouter);
app.use(subadminRequestsRouter);
app.use(subadminRouter);
app.use(authorityUserRequestsRouter);
app.use(eventRequestsRouter);
app.use(leaveApplicationsRouter);
// CORS handling for all request
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE");
res.header("Access-Control-Allow-Headers", "Content-Type");
next();
});
//starting the server
app.listen(port, () => {
console.log("Server listening on port ", port);
});