-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (55 loc) · 1.61 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
const express = require("express");
const cors = require("cors");
//create a server
const server = express();
//add cors
server.use(cors());
server.use(express.json());
//set hostname
const hostname = "localhost";
const PORT = 4333;
//Routes
server.get("/", function(request, response){
response.send("Welcome to Website");
})
//About Us
server.get("/about-us", function(request, response){
response.send("This is about us page");
})
//Contact Us
server.get("/contact-us", (request, response) => {
response.send("This is Contact Us Page");
})
//login user
server.post("/login-user", function(request, response){
console.log(request.body)
const username = request.body.username
const password = request.body.password
//
})
server.get("/api/news", function(request, response){
response.send({
message: "News retrieved",
data: [ {
'date': 'Jan 15, 2022',
'title': "Nigeria is a great country",
'content': "This is a great country ruled by a great leader",
'author': 'Lai Mohammed'
},
{
'date': 'Jan 16, 2022',
'title': "Nigeria is a bad country",
'content': "This is a bad country ruled by a great leader",
'author': 'Tru Mohammed'
},
{
'date': 'Jan 17, 2022',
'title': "Nigeria is a confused country",
'content': "This is a confused country ruled by a great leader",
'author': 'Garba Shehu'
}
]
})
})
//listen
server.listen(PORT, hostname, () => console.log(`Server running on http://${hostname}:${PORT}`))