Add config to API and output on /api/config

This commit is contained in:
30hours 2024-02-08 10:43:51 +00:00
parent 48638eacdc
commit f2b9e912ac
6 changed files with 75 additions and 23 deletions

View file

@ -8,6 +8,7 @@
"start": "node server.js"
},
"dependencies": {
"express": "^4.16.1"
"express": "^4.16.1",
"js-yaml": "^4.1.0"
}
}

View file

@ -1,6 +1,17 @@
const express = require('express');
const dgram = require('dgram');
const net = require("net");
const fs = require('fs');
const yaml = require('js-yaml');
const dns = require('dns');
// parse config file
var config;
try {
const file = process.argv[2];
config = yaml.load(fs.readFileSync(file, 'utf8'));
} catch (e) {
console.error('Error reading or parsing the YAML file:', e);
}
var stash_map = require('./stash/maxhold.js');
var stash_detection = require('./stash/detection.js');
@ -8,15 +19,14 @@ var stash_iqdata = require('./stash/iqdata.js');
var stash_timing = require('./stash/timing.js');
// constants
const PORT = 3000;
const HOST = '0.0.0.0';
const PORT = config.network.ports.api;
const HOST = config.network.ip;
var map = '';
var detection = '';
var track = '';
var timestamp = '';
var timing = '';
var iqdata = '';
var data = '';
var data_map;
var data_detection;
var data_tracker;
@ -56,6 +66,9 @@ app.get('/api/timing', (req, res) => {
app.get('/api/iqdata', (req, res) => {
res.send(iqdata);
});
app.get('/api/config', (req, res) => {
res.send(config);
});
// stash API
app.get('/stash/map', (req, res) => {
@ -86,7 +99,6 @@ app.listen(PORT, HOST, () => {
// tcp listener map
const server_map = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{
data_map = data_map + msg.toString();
if (data_map.slice(-1) === "}")
@ -99,11 +111,10 @@ const server_map = net.createServer((socket)=>{
console.log("Connection closed.");
})
});
server_map.listen(3001);
server_map.listen(config.network.ports.map);
// tcp listener detection
const server_detection = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{
data_detection = data_detection + msg.toString();
if (data_detection.slice(-1) === "}")
@ -116,11 +127,10 @@ const server_detection = net.createServer((socket)=>{
console.log("Connection closed.");
})
});
server_detection.listen(3002);
server_detection.listen(config.network.ports.detection);
// tcp listener tracker
const server_tracker = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{
data_tracker = data_tracker + msg.toString();
if (data_tracker.slice(-1) === "}")
@ -133,11 +143,10 @@ const server_tracker = net.createServer((socket)=>{
console.log("Connection closed.");
})
});
server_tracker.listen(3003);
server_tracker.listen(config.network.ports.track);
// tcp listener timestamp
const server_timestamp = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{
data_timestamp = data_timestamp + msg.toString();
timestamp = data_timestamp;
@ -147,11 +156,10 @@ const server_timestamp = net.createServer((socket)=>{
console.log("Connection closed.");
})
});
server_timestamp.listen(4000);
server_timestamp.listen(config.network.ports.timestamp);
// tcp listener timing
const server_timing = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{
data_timing = data_timing + msg.toString();
if (data_timing.slice(-1) === "}")
@ -164,11 +172,10 @@ const server_timing = net.createServer((socket)=>{
console.log("Connection closed.");
})
});
server_timing.listen(4001);
server_timing.listen(config.network.ports.timing);
// tcp listener iqdata metadata
const server_iqdata = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{
data_iqdata = data_iqdata + msg.toString();
if (data_iqdata.slice(-1) === "}")
@ -181,4 +188,5 @@ const server_iqdata = net.createServer((socket)=>{
console.log("Connection closed.");
})
});
server_iqdata.listen(4002);
server_iqdata.listen(config.network.ports.iqdata);

View file

@ -46,17 +46,30 @@ network:
timestamp: 4000
timing: 4001
iqdata: 4002
config: 4003
truth:
adsb:
enabled: false
ip: 0.0.0.0
port: 30000
ip: 'adsb.30hours.dev'
port: 80
ais:
enabled: false
ip: 0.0.0.0
port: 30001
location:
rx:
latitude: -34.9286
longitude: 138.5999
altitude: 50
name: "Adelaide"
tx:
latitude: -34.9810
longitude: 138.7081
altitude: 750
name: "Mount Lofty"
save:
iq: true
map: false

View file

@ -50,17 +50,30 @@ network:
timestamp: 4000
timing: 4001
iqdata: 4002
config: 4003
truth:
adsb:
enabled: false
ip: 0.0.0.0
port: 30000
ip: 'adsb.30hours.dev'
port: 80
ais:
enabled: false
ip: 0.0.0.0
port: 30001
location:
rx:
latitude: -34.9286
longitude: 138.5999
altitude: 50
name: "Adelaide"
tx:
latitude: -34.9810
longitude: 138.7081
altitude: 750
name: "Mount Lofty"
save:
iq: true
map: false

View file

@ -46,17 +46,30 @@ network:
timestamp: 4000
timing: 4001
iqdata: 4002
config: 4003
truth:
adsb:
enabled: false
ip: 0.0.0.0
port: 30000
ip: 'adsb.30hours.dev'
port: 80
ais:
enabled: false
ip: 0.0.0.0
port: 30001
location:
rx:
latitude: -34.9286
longitude: 138.5999
altitude: 50
name: "Adelaide"
tx:
latitude: -34.9810
longitude: 138.7081
altitude: 750
name: "Mount Lofty"
save:
iq: true
map: false

View file

@ -40,5 +40,9 @@ services:
restart: always
build: ./api
image: blah2_api
volumes:
- ./config:/usr/src/app/config
network_mode: host
command: >
sh -c "node server.js /usr/src/app/config/config.yml"
container_name: blah2-api