Skip to content

Commit 4de1dd0

Browse files
Merge pull request #5 from speedtracker/fix/connect_headers
Add Accept header to connect endpoint
2 parents 47df198 + 1de2eb7 commit 4de1dd0

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ server.post('/v1/test/:user/:repo/:branch/:profile', testHandler)
8282
// ------------------------------------
8383

8484
server.get('/v1/connect/:user/:repo', (req, res) => {
85-
const github = new GitHub()
85+
const github = new GitHub(GitHub.GITHUB_CONNECT)
8686

8787
github.authenticate(config.get('githubToken'))
8888

@@ -103,12 +103,14 @@ server.get('/v1/connect/:user/:repo', (req, res) => {
103103
} else {
104104
return Promise.reject()
105105
}
106-
}).then((response) => {
106+
}).then(response => {
107107
// Track event
108108
new Analytics().track(Analytics.Events.CONNECT)
109109

110110
res.send('OK!')
111-
}).catch((err) => {
111+
}).catch(err => {
112+
console.log(err.stack || err)
113+
112114
res.status(500).send('Invitation not found.')
113115
})
114116
})

lib/GitHub.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
const GitHubApi = require('github')
22

3-
const GitHub = function () {
3+
const GITHUB_CONNECT = 1
4+
5+
const GitHub = function (type) {
6+
let headers = {
7+
'user-agent': 'SpeedTracker agent'
8+
}
9+
10+
switch (type) {
11+
case GITHUB_CONNECT:
12+
headers['Accept'] = 'application/vnd.github.swamp-thing-preview+json'
13+
14+
break
15+
}
16+
417
this.api = new GitHubApi({
518
debug: (process.env.NODE_ENV !== 'production'),
619
debug: false,
720
protocol: 'https',
821
host: 'api.github.com',
922
pathPrefix: '',
10-
headers: {
11-
'user-agent': 'SpeedTracker agent'
12-
},
23+
headers,
1324
timeout: 5000,
1425
Promise: Promise
1526
})
@@ -25,3 +36,5 @@ GitHub.prototype.authenticate = function (token) {
2536
}
2637

2738
module.exports = GitHub
39+
40+
module.exports.GITHUB_CONNECT = GITHUB_CONNECT

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "speedtracker-api",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)