-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
60 lines (47 loc) · 1.81 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
const express = require("express")
const mongoose = require("mongoose")
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const Employee = require("./model/Employee.model")
const { requireAuth, checkEmployee, requireAdminAuth } = require('./middleware/authMiddleware');
const authRoutes = require("./route/authRoutes")
const employeeRoutes = require("./route/Employee.route")
const adminRoutes = require("./route/Admin.route")
const taskRoute = require("./route/Task.route")
const app = express()
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static('public'));
// support parsing of application/json type post data
app.use(bodyParser.json());
//support parsing of application/x-www-form-urlencoded post data
app.use(bodyParser.urlencoded({ extended: true }));
// app.use(bodyParser.urlencoded());
// view engine
app.set('view engine', 'ejs');
// database connection
const port = process.env.PORT || 3000
const dbURI = process.env.MONGODB_CONNECTION_URI
mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true})
.then((result) => app.listen(port, ()=> console.log(`Listening on port ${port}`)))
.catch((err) => console.log(err));
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
// console.log(year)
return [year, month, day].join('-');
}
app.use("/", authRoutes)
app.use("/admin", requireAdminAuth, adminRoutes)
app.use("/employee", requireAuth, employeeRoutes)
app.use("/task", requireAuth, taskRoute)
app.get("/", (req, res) => {
res.render("login", {msg:""})
})