*** WIP WIP *** woks now for live and havg

This commit is contained in:
rxf
2023-03-27 09:56:18 +02:00
parent 26e4b75a6f
commit 126acfeb7f
11 changed files with 498 additions and 99 deletions
+8 -34
View File
@@ -1,40 +1,14 @@
import express from 'express'
import * as tables from "../utilities/tables.js"
import { dispatchCommand } from "./api.js"
import {getData4map} from "../actions/data4map.js"
import * as cTable from "../utilities/commands.js"
import * as ERR from "../utilities/errortexts.js"
const router = express.Router();
/* GET home page. */
const chartapiRouter = express.Router();
// normal routes called from javascript client
router.get('/:cmd', async (req, res) => {
const cmd = req.params.cmd
let table
for (let c of cTable.chartcmdTable) {
if (c.cmd === cmd) {
let erg = await c.func(req.query)
if (typeof erg === 'string') {
res.type('text')
res.send(erg)
} else {
res.json(erg)
}
return
}
}
res.json({err: ERR.CMNDUNKOWN})
chartapiRouter.get('/:cmd', async (req, res) => {
const params = req.query
params.kind = 'chart'
await dispatchCommand(req.params.cmd, tables.cmdTable, params, res)
})
router.post('/:cmd', async (req, res) => {
const cmd = req.params.cmd
if (cmd === 'getdata4maps') {
const erg = await getData4map(req.body)
res.json(erg)
} else {
res.json({err: ERR.CMNDUNKOWN})
}
})
export default router
export default chartapiRouter