This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver.js
68 lines (59 loc) · 1.54 KB
/
server.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
const express = require("express");
const app = express();
app.use(express.json());
const mockUserData = [{
id: 1,
name: "Mark"
},
{
id: 2,
name: "Jill"
},
];
//added message and status
let testStatus = false;
const message = 'successfully got users. Nice!';
const status = true;
app.get("/users/:id", function (req, res) {
if (mockUserData.find((user) => user.id == req.params.id)) {
res.json({
success: status,
message: message,
user: mockUserData.find((user) => user.id == req.params.id)
});
} else {
id = req.params.id;
res.json({
success: testStatus,
message: `Sorry user doesn't exist for the id ${id}`
});
}
});
app.get("/users", function (req, res) {
res.json({
success: status,
message: message,
users: mockUserData,
});
});
app.post("/login", function (req, res) {
const username = req.body.username;
const password = req.body.password;
const mockUsername = "billyTheKid";
const mockPassword = "superSecret";
if (username === mockUsername && password === mockPassword) {
res.json({
success: status,
message: "password and username match!",
token: "encrypted token goes here",
});
} else {
res.json({
success: testStatus,
message: "password and username do not match",
});
}
});
app.listen(8000, function () {
console.log("server is running");
});