-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
78 lines (62 loc) · 2.23 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const express = require('express');
const app = express();
const cors = require('cors');
const port = 3000;
const Mongo = require('./mongoAPI');
const bodyParser = require('body-parser');
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use(cors());
app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
app.use(function (req, res, next) {
if (req.headers.authorization === process.env.API_KEY) {
next()
} else {
res.send({'error': 'Unauthorized'})
}
});
app.get('/', (req, res) => res.send('Hello World!'));
app.get('/apiaries', (req, res) => {
Mongo.getApiaries(req, (results) => res.send(results))
});
app.post('/addUser', (req, res) => {
Mongo.addUser(req.body, (results) => res.send(results))
});
app.get('/getUserInfo', (req, res) => {
Mongo.getUserInfo(req, (results) => res.send(results))
});
app.post('/addSwarmRetrievalZones', (req, res) => {
Mongo.addSwarmRetrievalZones(req.body, (results) => res.send(results))
});
app.post('/addApiary', (req, res) => {
Mongo.addApiary(req.body, (results) => res.send(results))
});
app.post('/addHive', (req, res) => {
Mongo.addHive(req.body, (results) => res.send(results))
});
app.post('/removeHive', (req, res) => {
Mongo.removeHive(req.body, (results) => res.send(results))
});
app.post('/addSwarm', (req, res) => {
Mongo.addSwarm(req.body, (results) => res.send(results))
});
app.get('/getSwarms', (req, res) => {
Mongo.getSwarms(req.body, (results) => res.send(results))
});
app.post('/claimSwarm', (req, res) => {
Mongo.claimSwarm(req.body, (results) => res.send(results))
});
app.post('/unclaimSwarm', (req, res) => {
Mongo.unclaimSwarm(req.body, (results) => res.send(results))
});
app.post('/swarmRetrieved', (req, res) => {
Mongo.swarmRetrieved(req.body, (results) => res.send(results))
});
app.post('/autonomousSwarmRetrieved', (req, res) => {
Mongo.autonomousSwarmRetrieved(req.body, (results) => res.send(results))
});
app.listen(process.env.PORT || 5000, () => console.log(`Example app listening at http://localhost:${port}`));