This repository has been archived by the owner on Jul 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
99 lines (79 loc) · 1.92 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
const express = require("express");
const app = express();
var cors = require('cors');
const fs = require('fs');
var port = 5000;
// Body parser
app.use(cors())
app.use(express.urlencoded({ extended: false }));
// Home route
app.get("/", (req, res) => {
res.send("Welcome to a basic express App");
});
// Mock API
app.get("/faq", (req, res) => {
fs.readFile(__dirname +"/faq.json", function (err,data) {
if (err) {
res.writeHead(404);
res.end(JSON.stringify(err));
return;
}
res.writeHead(200);
res.end(data);
});
});
app.get("/links", (req, res) => {
fs.readFile(__dirname +"/links.json", function (err,data) {
if (err) {
res.writeHead(404);
res.end(JSON.stringify(err));
return;
}
res.writeHead(200);
res.end(data);
});
});
app.get("/doctors", (req, res) => {
fs.readFile(__dirname +"/doctors.json", function (err,data) {
if (err) {
res.writeHead(404);
res.end(JSON.stringify(err));
return;
}
res.writeHead(200);
res.end(data);
});
});
app.get('/doctorsbyId', (req, res) => {
fs.readFile(__dirname +"/doctors.json", function (err,data) {
if (err) {
res.writeHead(404);
res.end(JSON.stringify(err));
return;
}
var doctors = JSON.parse(data.toString()).doctors;
var filteredDoctor = {};
if( typeof req.query.emailId != 'undefined' ){
filteredDoctor = doctors.filter(function(v, i) {
return ((v["emailaddress"] === req.query.emailId));
})
}
res.json(filteredDoctor)
});
});
app.get("/tnc", (req, res) => {
fs.readFile(__dirname +"/tnc.json", function (err,data) {
if (err) {
res.writeHead(404);
res.end(JSON.stringify(err));
return;
}
res.writeHead(200);
res.end(data);
});
});
// Listen on port 5000
app.listen(port, () => {
console.log(`Server is booming on port 5000
Visit http://localhost:5000`);
});