-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (34 loc) · 1.04 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
const app = require('express')()
const request = require('request')
const bodyParser = require('body-parser')
const upload = require('multer')()
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization')
res.header('Content-Type', 'application/json')
next()
})
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.post('*', upload.array(), (req, res) => {
let client_secret = process.env.CLIENT_SECRET
if (client_secret){
req.body.client_secret = client_secret
}
request.post({
url: 'https://github.com/login/oauth/access_token',
form: req.body,
headers: {
'Accept': 'application/json',
'User-Agent': 'gh-oauth-server',
},
}, (error, r, body) => {
if (!error) {
res.send(body)
} else {
res.json({ error })
}
})
})
const port = process.env.PORT || 3000
app.listen(port, () => console.log(`gh-oauth-server listening on port ${port}`))