-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
98 lines (90 loc) · 3.24 KB
/
index.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
const request = require('request')
const largeBadge = require('./js/large')
const mediumBadge = require('./js/medium')
const smallBadge = require('./js/small')
const githubInfo = require('./js/githubInfo')
const express = require('express')
const sslRedirect = require('heroku-ssl-redirect')
const app = express()
app.use(sslRedirect())
app.get('/', function (req, res) {
res.sendFile('/index.html', {root: __dirname})
})
app.get('/js/client.js', function (req, res) {
res.sendFile('/js/client.js', {root: __dirname})
})
app.get('/style/style.css', function (req, res) {
res.sendFile('/style/style.css', {root: __dirname})
})
app.get('/makebadge/small/:user/:repo', function (req, res) {
let svg = ''
request(`https://github.com/${req.params.user}/${req.params.repo}`, function (error, response, body) {
if (response !== undefined && response.statusCode >= 400) {
res.status(400).send('Invalid repository')
return
} else if (response === undefined) {
res.status(400).send('There was an error')
return
}
let info = githubInfo.getInfo(req.params.user, req.params.repo, function (error, result) {
if (error) {
res.status(400).send('Make sure repo is not empty')
return
}
svg = smallBadge.createSVG(result)
res.set('Content-Type', 'image/svg+xml')
res.set('Surrogate-Control', 'max-age=60')
res.set('Cache-Control', 'private')
res.send(svg)
})
})
})
app.get('/makebadge/medium/:user/:repo', function (req, res) {
let svg = ''
request(`https://github.com/${req.params.user}/${req.params.repo}`, function (error, response, body) {
if (response !== undefined && response.statusCode >= 400) {
res.status(400).send('Invalid repository')
return
} else if (response === undefined) {
res.status(400).send('There was an error')
return
}
let info = githubInfo.getInfo(req.params.user, req.params.repo, function (error, result) {
if (error) {
res.status(400).send('Make sure repo is not empty')
return
}
svg = mediumBadge.createSVG(result)
res.set('Content-Type', 'image/svg+xml')
res.set('Surrogate-Control', 'max-age=60')
res.set('Cache-Control', 'private')
res.send(svg)
})
})
})
app.get('/makebadge/:user/:repo', function (req, res) {
let svg = ''
request(`https://github.com/${req.params.user}/${req.params.repo}`, function (error, response, body) {
if (response !== undefined && response.statusCode >= 400) {
res.status(400).send('Invalid repository')
return
} else if (response === undefined) {
res.status(400).send('There was an error')
return
}
let info = githubInfo.getInfo(req.params.user, req.params.repo, function (error, result) {
if (error) {
res.status(400).send('Make sure repo is not empty')
return
}
svg = largeBadge.createSVG(result)
res.set('Content-Type', 'image/svg+xml')
res.set('Surrogate-Control', 'max-age=60')
res.set('Cache-Control', 'private')
res.send(svg)
})
})
})
app.listen(process.argv[2], function () {
console.log('running', process.argv[2])
})