-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (42 loc) · 1.38 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
const express = require("express"),
bodyParser = require("body-parser"),
app = express(),
request = require("request"),
swaggerUi = require("swagger-ui-express"),
swaggerDocument = require("./documentation.json");
const jsonParser = bodyParser.json();
const config = require("./config/config.js"),
eventsTransformer = require("./transformers/events");
app.use("/", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.post("/insights/:accountNumber/key/:xinsertkey", jsonParser, (req, res) => {
const accountNumber = req.params["accountNumber"];
const xInsertKey = req.params["xinsertkey"];
const insightEvent = eventsTransformer(req.body);
request.post(`${config.insights_host}/v1/accounts/${accountNumber}/events`, {
headers:
{
"X-Insert-Key": xInsertKey
},
json: insightEvent
}, (error, response, body) => {
if (error) {
res.json(
{
statusCode: 500,
message: error,
}
);
}
res.json(
{
statusCode: response.statusCode,
message: body,
}
);
});
});
app.listen(config.port, () => {
// eslint-disable-next-line no-console
console.log(`Server running on port ${config.port}`);
});
module.exports = app;