-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.js
44 lines (35 loc) · 1.05 KB
/
service.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
const url = require('url');
const https = require('https');
exports.sampleRequest = function (req, res) {
const reqUrl = url.parse(req.url, true);
var owner = 'avrillianz'; // default owner
var repository = 'Intention'; // default repository
if (reqUrl.query.owner) {
owner = reqUrl.query.owner
}
if (reqUrl.query.repo) {
repository = reqUrl.query.repo
}
var options = {
host: "api.github.com",
path: "/repos/" + owner + "/" + repository,
headers: {
"Accept": "application/vnd.github.v3+json",
'User-Agent': 'Localhost'
}
}
https.get(options, (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
console.log(JSON.stringify(data));
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.end(data);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
};