-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
60 lines (50 loc) · 2.35 KB
/
server.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
var express = require('express')
var app = express()
var bodyParser = require('body-parser')
var cors = require('cors')
//Get app resources
var SpeakerListResource = require('./speaker-list-resource');
var SubjectResource = require('./subject-resource');
var MessageResource = require('./message-resource');
var RepresentativesResource = require('./representatives-resource');
var StatisticsResource = require('./statistics-resource');
var OrganisationResource = require('./organisation-resource');
var HealthResource = require('./health-resource');
//Set server
var server = app.listen(8080, function() {
var host = server.address().address
var port = server.address().port
console.log('Listening at http://%s:%s', host, port)
})
//Use bodyparser and cors
app.use(bodyParser.json())
app.use(cors())
//Representatives endpoint
app.get('/representatives', RepresentativesResource.getAll)
app.get('/representatives/:speakerId', RepresentativesResource.get)
app.delete('/representatives/:speakerId', RepresentativesResource.delete)
app.delete('/representativesDeleteAll/IMSURE', RepresentativesResource.deleteAll)
app.post('/representatives', RepresentativesResource.add)
//Speakerlist endpoints
app.get('/speakerList', SpeakerListResource.getList)
app.post('/speakerList', SpeakerListResource.addSpeaker)
app.delete('/speakerList/:speakerRank', SpeakerListResource.removeSpeaker)
app.post('/speakerList/:speakerRank/replies', SpeakerListResource.addReply)
app.delete('/speakerList/:speakerRank/replies/:replyRank', SpeakerListResource.deleteReply);
app.post('/speakerList/:speakerRank', SpeakerListResource.nextSpeaker);
app.put('/speakerList/:oldPlace', SpeakerListResource.moveSpeaker);
//Subject endpoints
app.post('/subject', SubjectResource.set)
app.get('/subject', SubjectResource.get);
app.post('/message', MessageResource.set);
app.get('/message', MessageResource.get);
//Organisation endpoints
app.get('/organisations', OrganisationResource.get);
app.post('/organisations', OrganisationResource.add);
app.delete('/organisations/IMSURE/:id', OrganisationResource.delete);
//Statistics endpoints
app.get('/statistics/:field', StatisticsResource.getRankedListByField)
app.get('/statistics/:field/:fromDate', StatisticsResource.getRankedListByField)
app.get('/statistics/:field/:fromDate/:toDate', StatisticsResource.getRankedListByField)
//Healthcheck
app.get('/status', HealthResource.get);