-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
135 lines (118 loc) · 3.61 KB
/
index.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const express = require("express");
const cors = require("cors")
const fs = require('fs');
const app = express();
const session = require('express-session');
app.use(session({
secret: 'your-secret-key',
resave: false,
saveUninitialized: false
}));
const database = require("./config/database");
const cookieParser = require("cookie-parser");
const fileUpload = require("express-fileupload");
const dotenv = require("dotenv");
const userRoutes = require("./routes/user");
const caseRoutes = require("./routes/case");
const partyRoutes = require("./routes/party");
const docRoutes = require("./routes/doc");
const profileRoutes = require("./routes/profile");
const { auth } = require("./middlewares/auth");
const user = require("./models/user");
app.use(express.json());
app.use(cookieParser());
app.use(cors());
app.use(
fileUpload({
useTempFiles: true,
tempFileDir: "/tmp",
})
)
//EJS view engine setup
app.set('view engine', 'ejs');
app.use('/static', express.static('static'));
app.use('/records', express.static('Records'));
//User Interface Routes
app.get('/pages/home', (req, res) => {
res.render('index');
});
app.get('/pages/user-dashboard', auth, (req, res) => {
const token = req.query.token ||
req.cookies.token ||
req.body.token ||
req.header("Authorization").replace("Bearer ", "");
if(req.user.role=='Admin'){
res.render('admin',{intoken: token});
}
else {
res.render('user dashboard', { intoken: token });
}
});
app.get('/pages/party', auth, (req, res) => {
const token = req.query.token ||
req.cookies.token ||
req.body.token ||
req.header("Authorization").replace("Bearer ", "");
const caseID = req.query.caseID;
if (req.user.role == 'Client') {
res.render('client document', { intoken: token, incaseID: caseID });
};
if (req.user.role == 'Lawyer') {
res.render('lawyer document', { intoken: token, incaseID: caseID });
};
if (req.user.role == 'Judge') {
res.render('judge party', { intoken: token, incaseID: caseID });
};
})
app.get('/pages/judge-document', auth, (req, res) => {
const token = req.query.token ||
req.cookies.token ||
req.body.token ||
req.header("Authorization").replace("Bearer ", "");
const partyID = req.query.partyID;
res.render('judge document', { intoken: token, inpartyID: partyID });
})
app.get('/pages/doc-view', auth, (req, res) => {
const fileLink = req.query.fileLink;
const fileName = req.query.fileName;
const lastDotIndex = fileName.lastIndexOf('.');
const ext = lastDotIndex === -1 ? "" : fileName.slice(lastDotIndex + 1);
if(ext=='pdf' || ext=='docx'){
//for documents
res.render('pdf document',{fileLink:fileLink,fileName:fileName});
}
if(ext=='png' ||ext=='jpeg' || ext=='jfif' || ext=='jpg'){
//for images
res.render('image document',{fileLink:fileLink,fileName:fileName});
}
if(ext=='mkv' || ext=='mp4' || ext =='mov' || ext=='avi'){
//for videos
res.render('video document',{fileLink:fileLink,fileName:fileName});
}
});
dotenv.config();
const PORT = process.env.PORT || 3000;
//testing for video streaming
// app.get('/', (req, res) => {
// res.sendFile(__dirname + '/view/video testing.html');
// })
app.get('/notfound', (req, res) => {
res.status(404).send('Page Not Found');
});
//just paste it in the index.js file
app.use("/api/v1/auth", userRoutes);
app.use("/api/v1/case", caseRoutes);
app.use("/api/v1/party", partyRoutes);
app.use("/api/v1/doc", docRoutes);
app.use("/api/v1/user", profileRoutes);
//database connect
database.connect();
app.get("/", (req, res) => {
return res.json({
success: true,
message: 'Your server is up and running....'
});
});
app.listen(PORT, () => {
console.log(`App is running at ${PORT}`)
})