-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
87 lines (73 loc) · 2.14 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
const express = require('express');
const app = express();
const router = express.Router();
const path = require('path');
const fs = require('fs');
const user = require('./user.json')
/*
- Create new html file name home.html
- add <h1> tag with message "Welcome to ExpressJs Tutorial"
- Return home.html page to client
*/
router.get('/home', (req,res) => {
res.sendFile(path.join(__dirname, "/home.html"));
});
/*
- Return all details from user.json file to client as JSON format
*/
router.get('/profile', (req,res) => {
res.sendFile(path.join(__dirname, "./user.json"));
});
/*
- Modify /login router to accept username and password as query string parameter
- Read data from user.json file
- If username and passsword is valid then send response as below
{
status: true,
message: "User Is valid"
}
- If username is invalid then send response as below
{
status: false,
message: "User Name is invalid"
}
- If passsword is invalid then send response as below
{
status: false,
message: "Password is invalid"
}
*/
router.get('/login', (req,res) => {
let status = Boolean;
let message = "";
let response = {
status: status,
message: message
}
let username = user.username;
let password = user.password;
let queryUserName = req.query.username;
let queryPassword = req.query.password;
if(username === queryUserName && password === queryPassword){
response.status = true;
response.message = "User Is Valid"
}else if(username !== queryUserName){
response.status = false;
response.message = "User Name is Invalid"
}else{
response.status = false;
response.message = "Password is Invalid"
}
res.send(response);
});
/*
- Modify /logout route to accept username as parameter and display message
in HTML format like <b>${username} successfully logout.<b>
*/
router.get('/logout/:username', (req,res) => {
let username = req.params.username;
res.send(`<b>${username} successfully logout.</b>`);
});
app.use('/', router);
app.listen(process.env.port || 8081);
console.log('Web Server is listening at port '+ (process.env.port || 8081));