-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (34 loc) · 884 Bytes
/
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
const {
getStudentById,
getAllStudents,
addStudentEntry,
updateStudentEntry,
deleteStudentEntry,
getHealthCheck,
} = require("./api-handler");
const express = require("express");
const cors = require("cors");
const app = express();
const dotenv = require("dotenv");
dotenv.config();
app.use(
cors({
origin: "*", // for testing purpose
})
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const hostname = "127.0.0.1";
const port = 3000;
app.get("/v1/healthcheck", getHealthCheck);
app.get("/v1/students/:id", getStudentById);
app.route("/v1/students").get(getAllStudents);
app.route("/v1/students").post(addStudentEntry);
app
.route("/v1/students/:id")
.put(updateStudentEntry)
.delete(deleteStudentEntry);
app.listen(port, () => {
console.log(`server running on http://${hostname}:${port}`);
});
module.exports = app;