-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (69 loc) · 2.32 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
const express = require('express') ;
const cors = require('cors') ;
const { Model } = require('objection') ;
const Knex = require('knex');
const dbConfig = require('./knexfile').development ;
const courseRouter = require('./Courses/routes') ;
const ApplicationRouter = require('./Application/routes') ;
const instructorRouter = require('./Instructor/routes') ;
const commentRouter = require('./Comment/routes') ;
require('dotenv').config() ;
//--------------DB connection and config-----------------------//
const knex = Knex(dbConfig) ;
Model.knex(knex) ;
//------------------------------------------------------------//
const PORT = process.env.PORT || 8000 ;
const app = express() ;
app.use(cors()) ;
app.use(express.json())
//--------------ROUTES---------------//
app.use('/course' , courseRouter) ;
app.use('/application' , ApplicationRouter) ;
app.use('/instructor' , instructorRouter) ;
app.use('/comment' , commentRouter) ;
//---------------------------------//
app.get("/" , (req , res) => {
res.json({
message : {
description: "All supported endpoints : " ,
api: `http://localhost:${PORT}` ,
"/application": {
"/" : {
GET: "gets all applications" ,
POST: "creates applications"
},
"/:id" : {
GET: "gets application by id" ,
POST: "updates application status"
},
"/search?name=<name>&email=<email>" : {
GET: "get applications filtered according to query params"
}
} ,
"/comment": {
"/": {
GET: "gets all comments",
POST: "adds comment"
}
},
"/instructor": {
"/" : {
GET: "gets all instructors"
}
},
"/course": {
"/" : {
GET: "gets all courses" ,
POST: "create course"
} ,
"/:id" : {
GET: "get course by id",
POST: "update course by id"
}
}
}
})
}) ;
app.listen(PORT , () => {
console.log(`Server listening to port : ${PORT}`)
}) ;