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" "start": "node server.js"
}, },
"dependencies": { "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 express = require('express');
const dgram = require('dgram');
const net = require("net"); 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_map = require('./stash/maxhold.js');
var stash_detection = require('./stash/detection.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'); var stash_timing = require('./stash/timing.js');
// constants // constants
const PORT = 3000; const PORT = config.network.ports.api;
const HOST = '0.0.0.0'; const HOST = config.network.ip;
var map = ''; var map = '';
var detection = ''; var detection = '';
var track = ''; var track = '';
var timestamp = ''; var timestamp = '';
var timing = ''; var timing = '';
var iqdata = ''; var iqdata = '';
var data = '';
var data_map; var data_map;
var data_detection; var data_detection;
var data_tracker; var data_tracker;
@ -56,6 +66,9 @@ app.get('/api/timing', (req, res) => {
app.get('/api/iqdata', (req, res) => { app.get('/api/iqdata', (req, res) => {
res.send(iqdata); res.send(iqdata);
}); });
app.get('/api/config', (req, res) => {
res.send(config);
});
// stash API // stash API
app.get('/stash/map', (req, res) => { app.get('/stash/map', (req, res) => {
@ -86,7 +99,6 @@ app.listen(PORT, HOST, () => {
// tcp listener map // tcp listener map
const server_map = net.createServer((socket)=>{ const server_map = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{ socket.on("data",(msg)=>{
data_map = data_map + msg.toString(); data_map = data_map + msg.toString();
if (data_map.slice(-1) === "}") if (data_map.slice(-1) === "}")
@ -99,11 +111,10 @@ const server_map = net.createServer((socket)=>{
console.log("Connection closed."); console.log("Connection closed.");
}) })
}); });
server_map.listen(3001); server_map.listen(config.network.ports.map);
// tcp listener detection // tcp listener detection
const server_detection = net.createServer((socket)=>{ const server_detection = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{ socket.on("data",(msg)=>{
data_detection = data_detection + msg.toString(); data_detection = data_detection + msg.toString();
if (data_detection.slice(-1) === "}") if (data_detection.slice(-1) === "}")
@ -116,11 +127,10 @@ const server_detection = net.createServer((socket)=>{
console.log("Connection closed."); console.log("Connection closed.");
}) })
}); });
server_detection.listen(3002); server_detection.listen(config.network.ports.detection);
// tcp listener tracker // tcp listener tracker
const server_tracker = net.createServer((socket)=>{ const server_tracker = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{ socket.on("data",(msg)=>{
data_tracker = data_tracker + msg.toString(); data_tracker = data_tracker + msg.toString();
if (data_tracker.slice(-1) === "}") if (data_tracker.slice(-1) === "}")
@ -133,11 +143,10 @@ const server_tracker = net.createServer((socket)=>{
console.log("Connection closed."); console.log("Connection closed.");
}) })
}); });
server_tracker.listen(3003); server_tracker.listen(config.network.ports.track);
// tcp listener timestamp // tcp listener timestamp
const server_timestamp = net.createServer((socket)=>{ const server_timestamp = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{ socket.on("data",(msg)=>{
data_timestamp = data_timestamp + msg.toString(); data_timestamp = data_timestamp + msg.toString();
timestamp = data_timestamp; timestamp = data_timestamp;
@ -147,11 +156,10 @@ const server_timestamp = net.createServer((socket)=>{
console.log("Connection closed."); console.log("Connection closed.");
}) })
}); });
server_timestamp.listen(4000); server_timestamp.listen(config.network.ports.timestamp);
// tcp listener timing // tcp listener timing
const server_timing = net.createServer((socket)=>{ const server_timing = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{ socket.on("data",(msg)=>{
data_timing = data_timing + msg.toString(); data_timing = data_timing + msg.toString();
if (data_timing.slice(-1) === "}") if (data_timing.slice(-1) === "}")
@ -164,11 +172,10 @@ const server_timing = net.createServer((socket)=>{
console.log("Connection closed."); console.log("Connection closed.");
}) })
}); });
server_timing.listen(4001); server_timing.listen(config.network.ports.timing);
// tcp listener iqdata metadata // tcp listener iqdata metadata
const server_iqdata = net.createServer((socket)=>{ const server_iqdata = net.createServer((socket)=>{
socket.write("Hello From Server!")
socket.on("data",(msg)=>{ socket.on("data",(msg)=>{
data_iqdata = data_iqdata + msg.toString(); data_iqdata = data_iqdata + msg.toString();
if (data_iqdata.slice(-1) === "}") if (data_iqdata.slice(-1) === "}")
@ -181,4 +188,5 @@ const server_iqdata = net.createServer((socket)=>{
console.log("Connection closed."); console.log("Connection closed.");
}) })
}); });
server_iqdata.listen(4002); server_iqdata.listen(config.network.ports.iqdata);

View file

@ -46,17 +46,30 @@ network:
timestamp: 4000 timestamp: 4000
timing: 4001 timing: 4001
iqdata: 4002 iqdata: 4002
config: 4003
truth: truth:
adsb: adsb:
enabled: false enabled: false
ip: 0.0.0.0 ip: 'adsb.30hours.dev'
port: 30000 port: 80
ais: ais:
enabled: false enabled: false
ip: 0.0.0.0 ip: 0.0.0.0
port: 30001 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: save:
iq: true iq: true
map: false map: false

View file

@ -50,17 +50,30 @@ network:
timestamp: 4000 timestamp: 4000
timing: 4001 timing: 4001
iqdata: 4002 iqdata: 4002
config: 4003
truth: truth:
adsb: adsb:
enabled: false enabled: false
ip: 0.0.0.0 ip: 'adsb.30hours.dev'
port: 30000 port: 80
ais: ais:
enabled: false enabled: false
ip: 0.0.0.0 ip: 0.0.0.0
port: 30001 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: save:
iq: true iq: true
map: false map: false

View file

@ -46,17 +46,30 @@ network:
timestamp: 4000 timestamp: 4000
timing: 4001 timing: 4001
iqdata: 4002 iqdata: 4002
config: 4003
truth: truth:
adsb: adsb:
enabled: false enabled: false
ip: 0.0.0.0 ip: 'adsb.30hours.dev'
port: 30000 port: 80
ais: ais:
enabled: false enabled: false
ip: 0.0.0.0 ip: 0.0.0.0
port: 30001 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: save:
iq: true iq: true
map: false map: false

View file

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