forked from vatpac-technology/vatsim-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
209 lines (183 loc) · 5.23 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import express from 'express';
import cors from 'cors';
import { clearCache, cacheStats } from './client.js';
import {getPilots} from './pilots.js';
import { getATCSectors, getCoastline, getColours, getOnlinePositions } from './atc.js';
import { getAerodromes, getMajorAerodromes, getAerodromeBays } from './aerodrome.js';
import config from 'config';
import { getOSMAerodromeData } from './client.js';
import { getDataset } from './dataset.js';
const app = express()
const PORT = config.get('app.http.port');
const HOST = config.get('app.http.host');
var corsOptions = {
origin: '*',
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
}
app.get('/', cors(), async (req, res) => {
res.send(`
<html>
<head>
<title>VATPAC Map Service</title>
</head>
<body>
<ul>
<li><a href="/static/sectormap.html">ATC sector map</a></li>
<li><a href="/static/map.html?theme=light">Pilots map - light theme</a></li>
<li><a href="/static/map.html?theme=dark">Pilots map - dark theme</a></li>
</ul>
</body>
</html>
${config.get('app.name')} / ${config.get('app.version')} ${process.env.NODE_ENV || "dev"}
`);
});
app.use('/static', express.static('public'));
app.use('/favicon.ico', express.static('public/favicon.ico'));
app.use('/testdata', express.static('data'));
app.get('/v1/dataset', cors(), async (req, res) => {
var dataset = await getDataset();
if(dataset == false){
res.sendStatus(500);
}else{
res.send(dataset)
}
});
app.get('/v1/pilots', cors(), async (req, res) => {
var pilots = await getPilots();
if(pilots == false){
res.sendStatus(500);
}else{
res.send(pilots)
}
});
app.get('/v1/flights/callsign/:callsign', cors(), async (req, res) => {
const pilots = await getPilots();
const feature = pilots.features.find(e => e.properties.pilot.callsign == req.params.callsign)
if(feature == false){
res.sendStatus(500);
} else if(feature == undefined){
res.sendStatus(404);
}else{
res.send(feature.properties.pilot)
}
});
app.get('/v1/flights/cid/:cid', cors(), async (req, res) => {
const pilots = await getPilots();
const feature = pilots.features.find(e => e.properties.pilot.cid == req.params.cid)
if(feature == false){
res.sendStatus(500);
} else if(feature == undefined){
res.sendStatus(404);
}else{
res.send(feature.properties.pilot)
}
});
app.get('/v1/flights/arrivals/:icaoCode', cors(), async (req, res) => {
const pilotData = await getPilots();
var features = false;
var pilots = [];
try{
features = pilotData.features.filter(e => e.properties.pilot.flight_plan.arrival == req.params.icaoCode)
features.forEach(function(e){pilots.push(e.properties.pilot)})
} catch (e) {}
if(features == false){
res.sendStatus(500);
}else{
res.send(pilots)
}
});
app.get('/v1/flights/departures/:icaoCode', cors(), async (req, res) => {
const pilotData = await getPilots();
var features = false;
var pilots = [];
try{
features = pilotData.features.filter(e => e.properties.pilot.flight_plan.departure === req.params.icaoCode)
features.forEach(function(e){pilots.push(e.properties.pilot)})
} catch (e) {}
if(features == false){
res.sendStatus(500);
}else{
res.send(pilots)
}
});
app.get('/v1/atc/sectors', cors(), async (req, res) => {
var standardOnly = (req.query.standardOnly == undefined ? false : req.query.standardOnly.toString());
var sectors = await getATCSectors();
if (standardOnly == "true"){
sectors = sectors.filter(function(sector) {
return sector.standard_position == true;
});
}
if(sectors == false){
res.sendStatus(500);
}else{
res.send(sectors)
}
});
app.get('/v1/atc/online', cors(), async (req, res) => {
var sectors = await getOnlinePositions();
if(sectors == false){
res.sendStatus(500);
}else{
res.send(sectors)
}
});
app.get('/v1/aerodromes', cors(), async (req, res) => {
var data = await getAerodromes();
if(data == false){
res.sendStatus(500);
}else{
res.send(data)
}
});
app.get('/v1/aerodromes/bays', cors(), async (req, res) => {
var data = await getAerodromeBays();
if(data == false){
res.sendStatus(500);
}else{
res.send(data)
}
});
app.get('/v1/aerodromes/major', cors(), async (req, res) => {
var data = await getMajorAerodromes();
if(data == false){
res.sendStatus(500);
}else{
res.send(data)
}
});
// app.get('/v1/aerodromes/:icao', cors(), async (req, res) => {
// var data = await getAerodromes();
// if(data == false){
// res.sendStatus(500);
// }else{
// res.send(data)
// }
// });
app.get('/v1/atc/coastline', cors(), async (req, res) => {
var data = await getCoastline();
if(data == false){
res.sendStatus(500);
}else{
res.send(data)
}
});
app.get('/v1/atc/colours', cors(), async (req, res) => {
var data = await getColours();
if(data == false){
res.sendStatus(500);
}else{
res.send(data)
}
});
app.get('/v1/cache/clear', cors(), (req, res) => {
clearCache();
return res.sendStatus(200);
});
app.get('/v1/cache/stats', cors(), (req, res) => {
return res.send(cacheStats());
});
app.listen(PORT, HOST);
//console.log(`Running on http://${HOST}:${PORT}`);
// Fill OSM cache
getAerodromes();