-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats_controller.mjs
41 lines (34 loc) · 1.09 KB
/
stats_controller.mjs
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
import express from 'express';
import * as stats from './stats_model.mjs';
const PORT = 8000;
const app = express();
app.use(express.json());
app.post('/', (req, res) => {
console.log(`Request for ${req.body.distribution} distribution from ${req.headers['user-agent']}`)
let result = {}
// uniform distribution data
if (req.body.distribution === 'uniform') {
stats.uniformDist(req.body.params, req.body.multiplicity)
.then(data => {
result.data = data;
res.send(result);
})
.catch(error => {
res.status(500).json(error.message);
});
}
// normal distribution data
if (req.body.distribution === 'normal') {
stats.normalDist(req.body.params, req.body.multiplicity)
.then(data => {
result.data = data;
res.send(result);
})
.catch(error => {
res.status(500).json(error.message);
});
}
});
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}...`);
});