forked from hull-ships/hull-processor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (29 loc) · 1001 Bytes
/
server.js
File metadata and controls
37 lines (29 loc) · 1001 Bytes
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
import express from "express";
import ComputeHandler from "./actions/compute-handler";
import NotifyHandler from "./actions/notify-handler";
import devMode from "./dev-mode";
export default function Server(connector, options = {}) {
const app = express();
const { hostSecret } = options;
app.post("/compute", ComputeHandler({ hostSecret, connector }));
if (options.devMode) app.use(devMode());
connector.setupApp(app);
app.post("/batch", NotifyHandler);
app.post("/notify", NotifyHandler);
// Error Handler
app.use((err, req, res) => { // eslint-disable-line no-unused-vars
if (err) {
const data = {
status: err.status,
segmentBody: req.segment,
method: req.method,
headers: req.headers,
url: req.url,
params: req.params
};
req.hull.logger.error("Error ----------------", err.message, err.status, data);
}
return res.status(err.status || 500).send({ message: err.message });
});
return app;
}