4cea325f56
routes/api.js - check type of sensor - translate error message app.js - debug = false at i18n public/javascripts/chart_utilities.js - setter/getter for current Tab public/javascripts/global.js - settings dialog completely rearranged - if only sensorid is given, check type routes/index.js - set language to global variable views/index.pug - reaggange settings dialog - translate 'Error' views/layout.pug - load new datepicker (vanillajs-datepicker) public/javascripts/map.js - fetching from server refactored to function - reenable tabs after leaving map charts/preparecharts - typo public/javascripts/showcharts.js - loadAll extended to load also live and map public/stylesheets/style.sass - a few changes for settinds dialog locales/[de|en] - added a few words charts/utilities.js - setter and getter for language
62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
import express from 'express'
|
|
import axios from 'axios'
|
|
import * as prep from '../charts/preparecharts.js'
|
|
import { getLanguage } from '../charts/utilities.js'
|
|
import { translate as trans } from '../routes/index.js'
|
|
|
|
const router = express.Router()
|
|
|
|
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. */
|
|
router.get('/:cmd', async function(req, res, next) {
|
|
// req.i18n.changeLanguage(req.query.lng)
|
|
const cmd = req.params.cmd
|
|
const lng = getLanguage()
|
|
// console.log('api.js: cmd = ' + cmd + ', language = ' + lng)
|
|
let url = APIHOST
|
|
url += (req.originalUrl + `&lng=${lng}`)
|
|
try {
|
|
const response = await axios(encodeURI(url));
|
|
if (response.status !== 200) {
|
|
res.json({err: `${trans('ESYSCALL')} status=${response.status}`})
|
|
}
|
|
if(response.data.err) {
|
|
res.json(response.data)
|
|
return
|
|
}
|
|
if (cmd === 'getoneproperty') {
|
|
res.json(response.data)
|
|
return
|
|
}
|
|
const options = response.data.options
|
|
for(let x of disttable) {
|
|
if (x.type === options.data) {
|
|
let ret = x.func(options, response.data.values, req)
|
|
res.json(ret)
|
|
break;
|
|
}
|
|
}
|
|
} catch (e) {
|
|
res.json({err: `${trans('ESYSCALL')} ${e}`})
|
|
}
|
|
})
|
|
|
|
export default router
|
|
|
|
|
|
|
|
// ToDo
|
|
// Hier : getsensordata und getmapdata unterbringen und damit den externen Server aufrufen
|
|
|