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:
+18
-1
@@ -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}`})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user