-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdraw_tree.ts
More file actions
46 lines (40 loc) · 1.1 KB
/
draw_tree.ts
File metadata and controls
46 lines (40 loc) · 1.1 KB
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
/** @type {import('@sveltejs/kit').RequestHandler} */
// this file will handle the communication between the chosen backend and the detectree frontend
// first let's read the config file and load the connector accordingly. We could move this in the function if we want to reaload the file everytime
import fs from 'fs';
import YAML from 'yaml';
const configFile = fs.readFileSync('./schema.yml', 'utf8');
const config = YAML.parse(configFile);
const backendTypes = {
elastic: '../backend_adapters/elastic'
};
export async function post(request: any): Promise<any> {
const data = JSON.parse(await request.body);
if (!data) {
return {
status: 400
};
}
if (data['endpointID']) {
if (backendTypes[config.backend.type]) {
const backend = await import(backendTypes[config.backend.type]);
const graphData = await backend.query(
config,
data['endpointID'],
data['startDate'],
data['endDate']
);
return {
body: graphData
};
} else {
console.log(`[x] Unknown backend selected: ${config.backend.type}`);
return {
status: 400
};
}
}
return {
status: 500
};
}