-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
121 lines (102 loc) · 3.27 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
const express = require('express');
const app = express();
const path = require('path');
const config = require('dotenv').config({ path: './KEYS.env' });
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
plugins: [
new CopyWebpackPlugin({
patterns: [
{
from: 'node_modules/cesium/Build/Cesium/Workers',
to: 'Cesium/Workers',
},
{
from: 'node_modules/cesium/Build/Cesium/ThirdParty',
to: 'Cesium/ThirdParty',
},
{
from: 'node_modules/cesium/Build/Cesium/Assets',
to: 'Cesium/Assets',
},
{
from: 'node_modules/cesium/Build/Cesium/Widgets',
to: 'Cesium/Widgets',
},
],
}),
],
entry: './public/javascripts/tle.js',
output: {
filename: 'tle.js'
}
};
const cesiumApiKey = process.env.CESIUM_API_KEY;
// Serve static files from the "public" directory
app.use(express.static(path.join(__dirname, 'public')));
// Serve the index.html file
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.get('/get-cesium-config', (req, res) => {
const cesiumConfig = {
apiKey: cesiumApiKey,
};
res.json(cesiumConfig);
});
// Start the server
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
const { exec } = require('child_process');
app.get('/api/access/old/:param1/:param2/:param3/:param4/:param5/:param6/:param7', (req, res) => {
const tle1 = req.params.param1;
const tle2 = req.params.param2;
const position = req.params.param3;
const startDate = req.params.param4;
const endDate = req.params.param5;
const timeStep = req.params.param6;
const th = req.params.param7;
let response;
exec(`java -cp ${path.join(__dirname, 'java/satellite-tools.jar')} satellite.tools.Simulation "${tle1}" "${tle2}" "${position}" "${startDate}" "${endDate}" "${timeStep}" "${th}"`, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error}`);
return;
}
response = JSON.parse(stdout);
res.json(response);
});
});
app.get('/api/access/:param1/:param2/:param3/:param4/:param5/:param6/:param7', (req, res) => {
const api = "https://satellite-access-3-hwfyof24la-tl.a.run.app/api/access/";
const uri = [];
const tle1 = req.params.param1;
const tle2 = req.params.param2;
const position = req.params.param3;
const startDate = req.params.param4;
const endDate = req.params.param5;
const timeStep = req.params.param6;
const th = req.params.param7;
uri.push(tle1);
uri.push(tle2);
uri.push(position);
uri.push(startDate);
uri.push(endDate);
uri.push(timeStep);
uri.push(th);
const encodedArray = uri.map(element => encodeURIComponent(element));
const request = encodedArray.join('/');
fetch(api + request)
.then(response => {
console.log("Fetched access intervals: OK");
return response.json();
})
.then(jsonObject => {
res.json(jsonObject);
})
.catch(error => {
console.error('Error computing access intervals:', error);
res.status(500).json({ error: 'An error occurred while fetching data' });
});
});