-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (44 loc) · 1.14 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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.json());
const mockUserData=[
{name:'Mark'},
{name:'Jill'}
]
app.get('/users', function(req,res){
res.json({
success: true,
message: 'successfully got users. Nice!',
users: mockUserData
})
})
app.get('/users/:id', function(req,res){
console.log(req.params.id)
res.json({
success: true,
message: 'got one user',
users: req.params.id
})
})
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: true,
message: 'password and username match!',
token: 'encrypted token goes here'
})
} else {
res.json({
success: false,
message: 'password and username do not match'
})
}
})
app.listen(8000,function(){
console.log("server is running")
})