-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·62 lines (51 loc) · 2.25 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
61
62
var express = require('express');
var event = require('./routes/events');
var sub = require('./routes/subscriptions');
var signal = require('./routes/signals');
var signallog = require('./routes/signallog');
var logger = require('morgan');
var bodyParser = require('body-parser');
var mongo = require('mongodb').MongoClient;
mongo.BSONPure = require('bson').BSONPure;
var BSON = require('bson').BSONPure;
var dbutils = require('./lib/dbutils.js');
var mongoUri = process.env.USNB_MONGO_URI_NOTIFICATIONS;
var port = (process.env.USNB_NOTIFICATIONS_PORT);
var app = express();
mongo.connect(mongoUri, (err, database) => {
if (err) {
console.log('err');
throw err;
}
app.set('db', database);
console.log('About to start listening');
app.listen(port);
console.log('Listening on port: ', port);
});
app.use(logger('dev')); /* 'default', 'short', 'tiny', 'dev' */
app.use(bodyParser.json());
console.log('registering event routes with express');
app.get('/events', event.findAll);
app.get('/events/:id', event.findById);
app.post('/events', event.addEvent);
app.put('/events/:id', event.updateEvent);
app.delete('/events/:id', event.deleteEvent);
console.log('registering subscription routes with express');
app.get('/subscriptions', sub.findAll);
app.get('/subscriptions/user/:userId', sub.findByUserId);
app.get('/subscriptions/entity/:entityId/user/:userId', sub.findByUserEntity);
app.get('/subscriptions/entity/:entityId', sub.findByEntity);
app.put('/subscriptions/', sub.updateByEntityUserType);
app.delete('/subscriptions/', sub.deleteByEntityUserType);
app.get('/subscriptions/endpoint/:alert', sub.findByAlertEndpoint);
app.get('/subscriptions/:id', sub.findById);
app.post('/subscriptions', sub.addSubscription);
app.put('/subscriptions/:id', sub.updateSubscription);
app.delete('/subscriptions/:id', sub.deleteSubscription);
app.get('/subscriptions/:eid/:alert', sub.findByEventIdAndAlert);
app.put('/subscriptions/:eid/:alert', sub.updateSubscriptionByEventIdAndAlert);
app.delete('/subscriptions/:eid/:alert', sub.deleteSubscriptionByEventIdAndAlert);
console.log('registering signal routes with express');
app.post('/signals', signal.processSignal);
console.log('registering log routes with express');
app.get('/signallog', signallog.findRecent);