import express from 'express' import {getData4map} from "../actions/data4map.js" import * as ERR from "../utilities/errortexts.js" import * as getData from "../actions/getsensorData.js"; import * as getProps from "../actions/getproperties.js"; import * as getAKWs from "../actions/getAKWData.js"; import * as holAddr from "../actions/getaddress.js"; export const apiRouter = express.Router(); import { logit, logerror } from '../utilities/logit.js' const cmdTable = [ {cmd: 'getactdata', func: getData.getActData}, {cmd: 'getlongavg', func: getData.getLongAvg}, {cmd: 'getavgdata', func: getData.getAvgData}, {cmd: 'getoneproperty', func: getProps.getOneProperty}, {cmd: 'getakwdata', func: getAKWs.getakwdata}, {cmd: 'getaddress', func: holAddr.getAddress}, {cmd: 'getsensordata', func: getData.getSensorData}, {cmd: 'getmapdata', func: getData4map} ] export const dispatchCommand = async (cmd, table, params, res) => { for (let c of table) { if (c.cmd === cmd) { let erg = await c.func(params) if (typeof erg === 'string') { res.type('text') res.send(erg) } else { res.json(erg) } return } } res.json({err: ERR.CMNDUNKOWN}) } // normal routes called from javascript client apiRouter.get('/:cmd', async (req, res) => { const params = req.query params.chart = false await dispatchCommand(req.params.cmd, cmdTable, params, res) })