-
Notifications
You must be signed in to change notification settings - Fork 20
/
server.js
135 lines (115 loc) · 3.39 KB
/
server.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const { $HTTP_PORT, $NODE_ENV } = require("./config/config")
const {
$COVIZU_CONNECTION_URI, $ACTIVE_DATABASE, $COLLECTION__CLUSTERS
} = require('./config/dbconfig')
require("./globalVariables");
const compression = require('compression');
const express = require('express');
const app = express();
const { utcDate } = require('./server/utils')
var http = require('http');
app.use(compression());
app.use(express.static('.'));
let dbManager;
if ($NODE_ENV == 'TEST') {
const { TestDBManager } = require("./dbmanager_test");
dbManager = new TestDBManager();
dbManager.load_globalData();
}
if ($NODE_ENV == 'DEV' || $NODE_ENV == 'PROD') {
const { DBManager } = require("./dbmanager");
dbManager = new DBManager();
dbManager.set_dbUrl($COVIZU_CONNECTION_URI)
dbManager.set_dbName($ACTIVE_DATABASE)
dbManager.start()
}
app.get('/api/edgeList/:cindex', (req, res) => {
dbManager.get_edgeList(req.params.cindex).then(result=>{
res.send(result);
})
});
app.get('/api/points/:cindex', (req, res) => {
dbManager.get_points(req.params.cindex).then(result=>{
res.send(result);
})
});
app.get('/api/variants/:cindex', (req, res) => {
dbManager.get_variants(req.params.cindex).then(result=>{
res.send(result);
})
});
app.get('/api/lineage/:cindex', (req, res) => {
dbManager.get_lineage(req.params.cindex).then(result=>{
res.send(result);
})
});
app.get('/api/tips', (req, res) => {
dbManager.get_tips().then(result=>{
res.send(result);
})
});
app.get('/api/display/:cindex', (req, res) => {
dbManager.get_lineage(req.params.cindex).then(result => {
dbManager.get_display(result).then(display => {
res.send(display);
})
})
});
app.get('/api/df', (req, res) => {
dbManager.get_df().then(result=>{
res.send(result)
})
});
app.get('/api/xbb', (req, res) => {
dbManager.get_xbb_df().then(result=>{
res.send(result)
})
});
app.get('/api/regionmap', (req, res) => {
dbManager.get_regionMap().then(result=>{
res.send(result);
})
// res.send(dbManager.get_regionMap());
})
app.get('/api/cid/:accession', (req, res) => {
dbManager.get_accession(req.params.accession.toUpperCase()).then(result=>{
res.send(result);
})
});
// this endpoint serves a massive file ~60MB. should we keep it?
app.get('/api/cid', (req, res) => {
dbManager.get_cid().then(result=>{
res.send(result);
})
// res.send(dbManager.get_cid());
});
app.get('/api/lineagetocid', (req, res) => {
dbManager.get_lineageToCid().then(result=>{
res.send(result);
})
// res.send(dbManager.get_lineageToCid());
});
app.get('/api/recombtips', (req, res) => {
dbManager.get_recombinantTips().then(result=>{
res.send(result);
})
// res.send(dbManager.get_recombinantTips());
});
app.get('/api/searchHits/:query/:start/:end', (req, res) => {
const start_date = utcDate(req.params.start);
const end_date = utcDate(req.params.end);
const query = req.params.query.toLocaleLowerCase();
dbManager.get_searchHits(start_date, end_date, query).then(result=>{
res.send(result);
})
// res.send(dbManager.get_searchHits(start_date, end_date, query));
});
app.get('/api/getHits/:query', (req, res) => {
const term = req.params.query
dbManager.get_hits(term).then(result=>{
res.send(result);
})
// res.send(dbManager.get_hits(term));
});
var httpServer = http.createServer(app);
httpServer.listen($HTTP_PORT, () => console.log(`Listening on Port ${$HTTP_PORT}...`));