-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
95 lines (86 loc) · 2.41 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
const expressLayouts = require('express-ejs-layouts');
const mongoose = require('mongoose');
const flash = require('connect-flash'); /*required to store msgs in a session and show them later
(eg: the success msg after registering in this project).
Not the same as the other error msgs, as those were just rendering a view with those boxes.*/
const session = require('express-session');
const passport = require('passport');
const express = require('express');
const app = express();
app.get('/moyan',(res,req)=>{
res.render("add_case_pg1.js")
})
//passport config
require('./config/passport')(passport);
//db config
const db = require('./config/keys').MongoURI; //for MongoDB Atlas
// const db = 'mongodb://127.0.0.1:27017/court_case_management' //for local MongoDB
//db connection
mongoose.connect
(
db,
{
useNewUrlParser: true,
useUnifiedTopology: true
}
).then
(
() => console.log('MongoDB Atlas connected...')
// () => console.log('MongoDB Local connected...')
).catch
(
(err) => console.log(err)
);
//middleware
/*static folder to serve html, css and imgs*/
app.use(express.static(__dirname + '/public'));
/*ejs*/
app.use(expressLayouts);
app.set('view engine', 'ejs');
/*body parser*/
app.use(express.urlencoded({extended: false}));
/*express session*/
app.use
(
session
(
{
secret: require('./config/secret.js').secret,
resave: true,
saveUninitialized: true
}
)
);
/*passport - required for log in (authentication) - the position of these 2 lines matter. They should be below the session...*/
app.use(passport.initialize());
app.use(passport.session());
/*connect flash*/
app.use(flash());
/*Global var middleware for diff colours for diff msgs (error msgs, flash msgs, etc)*/
app.use
(
(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();
}
);
//Routes
app.use('/', require('./routes/index.js'));
app.use('/client', require('./routes/client.js'));
app.use('/lawyer', require('./routes/lawyer.js'));
app.use('/judge', require('./routes/judge.js'));
app.use('/chat', require('./routes/chat.js'));
const PORT = process.env.PORT || 5000;
app.listen
(
PORT,
(err) =>
{
if(err)
throw err;
console.log(`Server started on PORT ${PORT}...`);
}
);