Prepare charts moved from api server to here

route/api.js
   - new distriputer fpr chart preparation

appp.js
   - removed unnecessary calls

public/javascripts/map.js
   - changed /char/... call to /api/... call

charts/preparecharts
   - added

charts/utilities.js
   - added

public/javascripts/showcharts.js
   - changed /char/... call to /api/... call

routes/users.js
   - deleted
This commit is contained in:
rxf
2023-04-07 15:23:16 +02:00
parent cba929dac4
commit 22a6b9ab2c
7 changed files with 706 additions and 18 deletions
+18 -1
View File
@@ -1,10 +1,20 @@
import express from 'express'
import pkg from '../package.json' assert { type: "json" }
import axios from 'axios'
import * as prep from '../charts/preparecharts.js'
const router = express.Router()
const { name, version, date } = pkg
const disttable = [
{type: 'live', func: prep.liveData },
{type: 'havg', func: prep.havgData },
{type: 'davg', func: prep.davgData },
{type: 'daynight', func: prep.dayNightData },
{type: 'lden', func: prep.ldenData },
{type: 'map', func: prep.mapData },
]
let APIHOST = process.env.APIHOST || 'http://localhost:3004'
/* GET home page. */
@@ -22,7 +32,14 @@ router.get('/:cmd', async function(req, res, next) {
if (response.status !== 200) {
res.json({err: `Error from servercall: status = ${response.status}`})
}
res.json(response.data)
const options = response.data.options
for(let x of disttable) {
if (x.type === options.data) {
let ret = x.func(options, response.data.values)
res.json(ret)
break;
}
}
} catch (e) {
res.json({err: `Error from servercall: ${e}`})
}
-9
View File
@@ -1,9 +0,0 @@
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond with a resource');
});
module.exports = router;