-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
39 lines (35 loc) · 1.11 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
var eventConsumer = require("commons/event-consumer");
var components = require("./components");
var logic;
var logger;
var util;
var http = require("http");
function processEvent(event) {
var eventStr = util.getEventString(event);
return util.extractPath(event).then(path => {
var rule = logic[path];
if (rule) {
return Promise.resolve().then(() => rule(event))
.then(() => logger.info("RECEIVED EVENT:", path))
.catch(err => logger.error(`EVENT ${eventStr} PATH ${path} ERROR: ${err}`));
}
})
.catch(err => logger.error(err));
}
components.init().then(() => {
var config = components.config;
logger = components.logger;
logic = require("./extra");
util = require("./util");
const server = http.createServer((req, res) => {
if (req.method === 'GET' && req.url === '/healthcheck') {
res.statusCode = 200;
} else {
res.statusCode = 404;
}
res.end();
}).listen(config.port);
eventConsumer(config, processEvent, error => {
logger.error(error);
});
});