-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
130 lines (116 loc) · 2.85 KB
/
app.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const express = require("express");
const app = express();
const fs = require("fs");
const bodyParser = require("body-parser");
const helmet = require("helmet");
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const API_BASE_URL = "https://api.github.com/";
// Use Helmet!
app.use(helmet());
app.get("/", (req, res) => {
res.send(
"Hello world! Our app is now wearing a Helmet for security reasons."
);
});
app.get("/search-users/:query", function (req, res) {
const queryParam = req.params.query;
const query = "siddhant";
const target = "name";
const type = "user";
const aprUrl = API_BASE_URL.concat(
"search/users?q=",
queryParam,
" in:",
target,
" type:",
type
);
fetch(aprUrl)
.then((res) => res.json())
.then(
(result) => {
res.send(result);
},
(error) => {
res.send(error);
}
);
});
app.get("/get-user-details/:login", function (req, res) {
const login = req.params.login;
const aprUrl = API_BASE_URL.concat("users/", login);
fetch(aprUrl)
.then((res) => res.json())
.then(
(result) => {;
res.send(result);
},
(error) => {
console.log(error);
res.send(error);
}
);
});
app.get("/get-user-repos/:login", function (req, res) {
const login = req.params.login;
const aprUrl = API_BASE_URL.concat("users/", login, "/repos");
fetch(aprUrl)
.then((res) => res.json())
.then(
(result) => {
res.send(result);
},
(error) => {
console.log(error);
res.send(error);
}
);
});
app.get("/get-repo-details/:login/:repo", function (req, res) {
const login = req.params.login;
const repo = req.params.repo;
const aprUrl = API_BASE_URL.concat("repos/", login, "/", repo);
fetch(aprUrl)
.then((res) => res.json())
.then(
(result) => {
res.send(result);
},
(error) => {
console.log(error);
res.send(error);
}
);
});
app.get("/get-repo-commits/:login/:repo", function (req, res) {
const login = req.params.login;
const repo = req.params.repo;
const aprUrl = API_BASE_URL.concat("repos/", login, "/", repo, "/commits");
fetch(aprUrl)
.then((res) => res.json())
.then(
(result) => {;
res.send(result);
},
(error) => {
console.log(error);
res.send(error);
}
);
});
app.listen(8080, function () {
console.log("Example app listening on port 8080!");
});
app.get("*", function (req, res, next) {
let err = new Error("Sorry! Can't find that resource. Please check your URL");
err.statusCode = 404;
next(err);
});
/*
USEFUL LINKS
https://docs.github.com/en/rest/quickstart
https://stateful.com/blog/github-search-api
https://youtu.be/7YeOjmpQUnU?si=QOLx_ONFJB40UbRI
https://youtu.be/EvZ6pjgYA38?si=GFX9OmhZHRAAcvP_
*/