-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (32 loc) · 805 Bytes
/
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
const http = require("http");
const request = require("request");
require("dotenv").config();
const clientId = process.env.REACT_APP_CLIENT_ID;
const secretKey = process.env.REACT_APP_SECRET_KEY;
console.log("started server on port 5003");
http
.createServer((req, res) => {
var code = req.url.split("=")[1];
if (code) {
request.post(
"https://github.com/login/oauth/access_token",
{
form: {
client_id: clientId,
client_secret: secretKey,
code: code
}
},
(err, r, body) => {
res.writeHead(301, {
Location: "http://localhost:3000?" + body
});
res.end();
}
);
} else {
res.writeHead(404);
res.end();
}
})
.listen(5003);