-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
35 lines (30 loc) · 971 Bytes
/
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
const app = require('express')();
const run = require('./src/monitor');
module.exports = function (config) {
if (!config.projects && config.project && config.filters) {
//TODO should I deprecate the old way? This is backwards compatibility for a simpler config model
//I think it's nice to be liberal in what we accept
config.projects = [{
project: config.project,
filters: config.filters
}];
}
app.use((req, res, next) => {
if (config.WSM_AUTH_KEY && req.headers['x-wsm_auth_key'] !== config.WSM_AUTH_KEY) {
res.sendStatus(403);
throw new Error(`Request denied from ${req.ip}`, req.headers);
}
next();
});
app.route('/')
.post((req, res) => {
run({debug: req.query.debug, config})
.then(data => res.send(req.query.debug ? data : {}))
.catch(ex => {
res.status(500)
.send(ex.stack ? ex.stack : ex);
throw ex;
});
});
return app;
};