-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (45 loc) · 1.27 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
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const Spinner = require('./spinner');
const port = 3000;
const auth = require('/auth_token').token;
let spinner = null;
// Init middliware
app.use(bodyParser.json());
app.use((req, res, next) => {
let auth_header = req.header('Auth');
if (auth_header === auth) {
next();
} else {
res.status(401).send();
}
});
app.post('/deploy', (req, res) => {
if (!spinner) {
spinner = new Spinner();
if (!req.body.cluster_name) {
spinner = null;
res.status(400).send({ message: 'cluster_name is required' });
} else {
spinner.scheduleDeployment(req.body, ()=>{});
res.status(200).send();
}
} else {
res.status(409).send({ message: 'Another build is running' });
}
});
app.get('/status', (req, res) => {
if (spinner) {
let status = spinner.getStatus();
res.status(200).send({ status: status });
} else {
res.status(200).send({ code: 'READY' });
}
});
app.listen(port, (err) => {
if (err) {
return console.error(err);
}
console.log(`Spinner is listening on ${port}`);
});