import express from 'express' import {getData4map} from "../actions/data4map.js" import * as cTable from "../utilities/commands.js" import * as ERR from "../utilities/errortexts.js" export const apiRouter = express.Router(); export const dispatchCommand = async (cmd, table, query, res) => { for (let c of table) { if (c.cmd === cmd) { let erg = await c.func(query) 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) => { await dispatchCommand(req.params.cmd, cTable.cmdTable, req.query, res) })