-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (58 loc) · 1.26 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
import express from "express"
import { default as controller } from "./controller/index.js"
import { default as middleware } from "./middleware/index.js"
const app = express()
const PORT = 8080
const SERVICE = "exams-app-backend"
app.listen(PORT, () => console.log(`app listening on port ${PORT}`))
app.use(
express.json(),
middleware.db.connectToDb,
)
// open endpoints
app.post(
`/${SERVICE}/login`,
controller.auth.login,
)
app.post(
`/${SERVICE}/register`,
controller.auth.register,
)
// jwt endpoints
app.use(
`/${SERVICE}/jwt-any/*`,
middleware.auth.verifyJwtAll,
)
app.get(
`/${SERVICE}/jwt-any/get-all-exams`,
controller.db.getAllExams
)
app.get(
`/${SERVICE}/jwt-any/get-submissions`,
controller.db.getAllSubmissions
)
app.post(
`/${SERVICE}/jwt-any/post-submission`,
controller.db.addSubmission
)
// jwt AND lecturer endpoints
app.use(
`/${SERVICE}/jwt-lecturer/*`,
middleware.auth.verifyJwtLecturer,
)
app.get(
`/${SERVICE}/jwt-lecturer/get-authored-exams`,
controller.db.getUserExams,
)
app.post(
`/${SERVICE}/jwt-lecturer/post-exam`,
controller.db.addExam
)
app.post(
`/${SERVICE}/jwt-lecturer/delete-exam`,
controller.db.deleteExam
)
app.post(
`/${SERVICE}/jwt-lecturer/update-exam`,
controller.db.updateExam
)