-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
63 lines (52 loc) · 1.36 KB
/
app.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
const express = require('express')
const bodyParser = require('body-parser')
const runner = require('./deploymentRunner')
const crypto = require('crypto')
require('log-timestamp')
const port = process.env.DEPLOYER_PORT || 3333
const app = express()
app.use(bodyParser.json())
app.post('/deploy', (req, res) => {
req.body.deploy.id = req.body.deploy.id || randomId()
console.log(`starting new deploy: ${JSON.stringify(req.body.deploy.id)}`)
if (runner.start(req.body.deploy)) {
res.send(req.body.deploy.id)
} else {
res.status(409)
res.send('A deploy is already running')
}
})
app.get('/deploy/:id/status', (req, res) => {
try {
runner.find(req.params.id)
} catch (err) {
res.status(404)
res.send(err.toString())
return
}
res.send(runner.status(req.params.id))
})
app.get('/deploy/:id/success', (req, res) => {
try {
runner.find(req.params.id)
} catch (err) {
res.status(404)
res.send(err.toString())
return
}
res.send(runner.success(req.params.id))
})
app.get('/deploy/:id/output', (req, res) => {
try {
runner.find(req.params.id)
} catch (err) {
res.status(404)
res.send(err.toString())
return
}
res.send(runner.output(req.params.id))
})
app.listen(port, () => console.log(`Deployer listening on port ${port}!`))
function randomId () {
return crypto.randomBytes(16).toString('hex')
}