Some errors fixed, works for api.js

This commit is contained in:
rxf
2023-03-24 15:30:41 +01:00
parent c4c90b4455
commit 26e4b75a6f
7 changed files with 134 additions and 76 deletions
+40
View File
@@ -0,0 +1,40 @@
import express from 'express'
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. */
// 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})
})
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