forked from sharedstreets/mobility-metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
38 lines (29 loc) · 1016 Bytes
/
server.ts
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
import * as fs from "fs";
import { H3AvailabilityStatusAggregator } from "./src/metrics/status";
const { fork } = require('child_process');
const { join } = require('path');
var cors = require('cors')
const express = require('express');
const app = express();
app.use(cors())
// boot the mds data processor
const childProcess = fork('mds_processor.ts');
var port = '8082';
app.get('/metric/:metric/:week/:period', async (req, res) =>
{
if(req.params.week && req.params.period) {
var weeks = [req.params.week];
var period = req.params.period;
if(req.params.metric === 'h3_availability') {
var availabilityStatus = new H3AvailabilityStatusAggregator();
try {
var geoJson = availabilityStatus.getGeoJson(weeks,period);
res.send(geoJson);
}
catch(e) {
console.log(e);
}
}
}
});
app.listen(port, () => console.log(`app listening on port ${port}!`));