-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
115 lines (107 loc) · 3.01 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
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
let express = require('express');
let cors = require('cors');
let axios = require('axios');
const bodyParser = require('body-parser');
require('dotenv').config({path:__dirname+'/.env'})
let app = express();
app.use(cors());
app.use(bodyParser.json());
let client_secret = `${process.env.CLIENT_SECRET}`;
let client_id = "b2fa34376e313b7517ec";
let api = "https://api.github.com";
app.get('/auth', (req, res) => {
let code = req.query.code;
axios.post('https://github.com/login/oauth/access_token', {
client_id: client_id,
client_secret: client_secret,
code: code
}, {
headers: {
accept: 'application/json'
}
}).then((response) => {
console.log(response.data);
res.send(response.data);
}
).catch((error) => {
console.log(error);
})
});
app.get('/user', (req, res) => {
let token = req.query.token;
axios.get(`${api}/user`, {
headers: {
Authorization: `Bearer ${token}`
}
}).then((response) => {
res.send(response.data);
}).catch((error) => {
res.send(error);
})
})
app.get('/repos', (req, res) => {
let token = req.query.token;
let username = req.query.username;
let per_page = req.query.per_page;
let page = req.query.page || 1;
let type = req.query.type || "all";
axios.get(`${api}/users/${username}/repos?per_page=${per_page}&page=${page}&type=${type}`, {
headers: {
Authorization: `Bearer ${token}`,
accept: 'application/vnd.github.v3+json'
}
}).then((response) => {
res.send(response.data);
}).catch((error) => {
res
})
})
app.get('/commits', (req, res) => {
let token = req.query.token;
let owner = req.query.owner;
let repo = req.query.repo;
axios.get(`${api}/repos/${owner}/${repo}/commits`, {
headers: {
Authorization: `Bearer ${token}`,
accept: 'application/vnd.github.v3+json'
}
}).then((response) => {
res.send(response.data);
}).catch((error) => {
res
})
})
app.get('/files', (req, res) => {
let token = req.query.token;
let owner = req.query.owner;
let repo = req.query.repo;
let path = req.query.path;
axios.get(`${api}/repos/${owner}/${repo}/contents/${path}`, {
headers: {
Authorization: `Bearer ${token}`,
accept: 'application/vnd.github.v3+json'
}
}).then((response) => {
res.send(response.data);
}).catch((error) => {
res
})
})
app.get('/pulls', (req, res) => {
let token = req.query.token;
let owner = req.query.owner;
let repo = req.query.repo;
axios.get(`${api}/repos/${owner}/${repo}/pulls`, {
headers: {
Authorization: `Bearer ${token}`,
accept: 'application/vnd.github+json'
}
}).then((response) => {
res.send(response.data);
}).catch((error) => {
res
})
})
app.listen(5000, () => {
console.log('Server started on port 5000');
});