Viele Updates, Version angepasst
This commit is contained in:
Vendored
+4
-1
@@ -11,7 +11,10 @@
|
|||||||
"skipFiles": [
|
"skipFiles": [
|
||||||
"<node_internals>/**"
|
"<node_internals>/**"
|
||||||
],
|
],
|
||||||
"program": "${workspaceFolder}/bin/www.js"
|
"program": "${workspaceFolder}/bin/www.js",
|
||||||
|
"env": {
|
||||||
|
"APIHOST": "https://sensorapi.fuerst-stuttgart.de"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
FROM node:18-alpine
|
||||||
|
|
||||||
|
ADD package.json /tmp/package.json
|
||||||
|
RUN cd /tmp && npm install
|
||||||
|
RUN mkdir -p /opt/app && cp -a /tmp/node_modules /tmp/package.json /opt/app/
|
||||||
|
WORKDIR /opt/app
|
||||||
|
ADD . /opt/app/
|
||||||
|
|
||||||
|
RUN apk add --no-cache tzdata
|
||||||
|
ENV TZ Europe/Berlin
|
||||||
|
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||||
|
|
||||||
|
RUN deluser --remove-home node
|
||||||
|
|
||||||
|
RUN touch cmds.sh \
|
||||||
|
&& echo 'npm start' >>cmds.sh
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD sh ./cmds.sh
|
||||||
|
|
||||||
@@ -38,6 +38,9 @@ app.set('view engine', 'pug');
|
|||||||
|
|
||||||
app.get('*', (req, res, next) => {
|
app.get('*', (req, res, next) => {
|
||||||
const subdom = req.headers.host.split('.')
|
const subdom = req.headers.host.split('.')
|
||||||
|
if (subdom[0] === 'laerm') {
|
||||||
|
subdom[0] = 'noise'
|
||||||
|
}
|
||||||
app.set('category',subdom[0])
|
app.set('category',subdom[0])
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
@@ -49,6 +52,7 @@ app.use(cookieParser());
|
|||||||
app.use(express.static(path.join(__dirname, 'public')));
|
app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
|
||||||
app.use('/api', apiRouter)
|
app.use('/api', apiRouter)
|
||||||
|
app.use('/srv', apiRouter)
|
||||||
app.use('/', indexRouter.router);
|
app.use('/', indexRouter.router);
|
||||||
|
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
|
|||||||
Executable
+63
@@ -0,0 +1,63 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Build Docker-Container
|
||||||
|
#
|
||||||
|
# Call: buildit.sh name [target]
|
||||||
|
#
|
||||||
|
# The Dockerfile must be named like Dockerfile_name
|
||||||
|
#
|
||||||
|
# 2018-09-20 rxf
|
||||||
|
# - before sending docker image to remote, tag actual remote image
|
||||||
|
#
|
||||||
|
# 2018-09-14 rxf
|
||||||
|
# - first Version
|
||||||
|
#
|
||||||
|
|
||||||
|
set -x
|
||||||
|
port=""
|
||||||
|
orgName=noise
|
||||||
|
name=noise
|
||||||
|
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
echo "Usage build_and_copy.sh [-p port] [-n name] target"
|
||||||
|
echo " Build docker container $name and copy to target"
|
||||||
|
echo "Params:"
|
||||||
|
echo " target: Where to copy the container to "
|
||||||
|
echo " -p port: ssh port (default 22)"
|
||||||
|
echo " -n name: new name for container (default: $orgName)"
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts n:p:h? o
|
||||||
|
do
|
||||||
|
case "$o" in
|
||||||
|
n) name="$OPTARG";;
|
||||||
|
p) port="-p $OPTARG";;
|
||||||
|
h) usage; exit 0;;
|
||||||
|
*) usage; exit 1;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
if [[ -z "$target" ]]; then
|
||||||
|
target=$1
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
echo "bad option $1"
|
||||||
|
# exit 1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
docker build -f Dockerfile_$orgName -t $name .
|
||||||
|
|
||||||
|
dat=`date +%Y%m%d%H%M`
|
||||||
|
|
||||||
|
if [ "$target" == "localhost" ]
|
||||||
|
then
|
||||||
|
docker tag $name $name:V_$dat
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
ssh $port $target "docker tag $name $name:V_$dat"
|
||||||
|
docker save $name | bzip2 | pv | ssh $port $target 'bunzip2 | docker load'
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
####Neues Sensor-API
|
||||||
|
|
||||||
|
* Programm **sensor_web_api**. Läuft auf Port 3000
|
||||||
|
* Aufruf über: **laerm.test.me:3000** (oder feinstaub.test... oder multigeiger.test...)
|
||||||
|
* Zugriff auf die DB mit dem Programm **SensorApi**. Dieses reagiert auf Port 3005 und muss im Hintergrund laufen!
|
||||||
+3
-3
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "laerm-web-sensorapi",
|
"name": "laerm-web-sensorapi",
|
||||||
"version": "3.0.4",
|
"version": "3.0.5",
|
||||||
"date": "2023-04-24 18:00 UTC",
|
"date": "2023-11-12 10:00 UTC",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node bin/www.js >>log/laerm_web.log 2>&1"
|
"start": "node bin/www.js >>/var/log/noise.log 2>&1"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export const noise_ymin = 30; // lowest value on y-axis for n
|
|||||||
export const noise_ymax = 120; // highest value on y-axis for noise
|
export const noise_ymax = 120; // highest value on y-axis for noise
|
||||||
export let peaklim = 70; // threshold for peak count
|
export let peaklim = 70; // threshold for peak count
|
||||||
|
|
||||||
export const url = '/api'
|
export const url = '/srv'
|
||||||
|
|
||||||
export function createGlobObtions() {
|
export function createGlobObtions() {
|
||||||
// Options, die für alle Plots identisch sind
|
// Options, die für alle Plots identisch sind
|
||||||
@@ -217,7 +217,7 @@ export const fetchfromserver = async (url) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const addAddress = async (sid) => {
|
export const addAddress = async (sid) => {
|
||||||
let url = `/api/getaddress?sensorid=${sid}`
|
let url = `/srv/getaddress?sensorid=${sid}`
|
||||||
let erg = await fetchfromserver(url)
|
let erg = await fetchfromserver(url)
|
||||||
if (!erg.err) {
|
if (!erg.err) {
|
||||||
return erg.address
|
return erg.address
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ import {setCurrentTab, getCurrentTab, showError, fetchfromserver} from "./chart_
|
|||||||
})
|
})
|
||||||
|
|
||||||
const getSensorType = async (sid) => {
|
const getSensorType = async (sid) => {
|
||||||
let url = `/api/getoneproperty?sensorid=${sid}`
|
let url = `/srv/getoneproperty?sensorid=${sid}`
|
||||||
const data = await fetchfromserver(url)
|
const data = await fetchfromserver(url)
|
||||||
return data.props.type
|
return data.props.type
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ const mapparams = {
|
|||||||
bounds: null,
|
bounds: null,
|
||||||
popuptext: '',
|
popuptext: '',
|
||||||
clickedSensor: 0,
|
clickedSensor: 0,
|
||||||
APIURL: '/api/getmapdata?',
|
APIURL: '/srv/getmapdata?',
|
||||||
MAXZOOM: 19
|
MAXZOOM: 19
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function showMap(params) {
|
export async function showMap(params) {
|
||||||
if(sysparams.category === 'laerm') {
|
if(sysparams.category === 'noise') {
|
||||||
utils.removeTabs()
|
utils.removeTabs()
|
||||||
if(mapparams.map && mapparams.map.remove) {
|
if(mapparams.map && mapparams.map.remove) {
|
||||||
mapparams.map.off();
|
mapparams.map.off();
|
||||||
@@ -36,7 +36,7 @@ export async function showMap(params) {
|
|||||||
await buildMarkers(params, mapparams)
|
await buildMarkers(params, mapparams)
|
||||||
});
|
});
|
||||||
|
|
||||||
if(sysparams.category === 'laerm') {
|
if(sysparams.category === 'noise'){
|
||||||
mapn.buildLegend(mapparams)
|
mapn.buildLegend(mapparams)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ export async function showMap(params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const buildMarkers = async (params, mapparams) => {
|
const buildMarkers = async (params, mapparams) => {
|
||||||
if(sysparams.category === 'laerm') {
|
if(sysparams.category === 'noise') {
|
||||||
return mapn.buildMarkers(params, mapparams)
|
return mapn.buildMarkers(params, mapparams)
|
||||||
} else if(sysparams.category === 'multigeiger') {
|
} else if(sysparams.category === 'multigeiger') {
|
||||||
return mapg.buildMarkers(params, mapparams)
|
return mapg.buildMarkers(params, mapparams)
|
||||||
|
|||||||
@@ -57,9 +57,9 @@ export async function buildMarkers(params, mpp) {
|
|||||||
if ((params.weeks > 0) && (x.weeks > params.weeks)) {
|
if ((params.weeks > 0) && (x.weeks > params.weeks)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// if (x.value <= -4) {
|
if (x.value <= -5) {
|
||||||
// continue
|
continue
|
||||||
// }
|
}
|
||||||
let marker = L.marker([x.location[1], x.location[0]], {
|
let marker = L.marker([x.location[1], x.location[0]], {
|
||||||
icon: new L.Icon({
|
icon: new L.Icon({
|
||||||
iconUrl: buildIcon(getColor(parseInt(x.value)), 0, x.indoor),
|
iconUrl: buildIcon(getColor(parseInt(x.value)), 0, x.indoor),
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import * as utils from "./chart_utilities.js"
|
|||||||
import * as dt from './datetime.js'
|
import * as dt from './datetime.js'
|
||||||
|
|
||||||
function getColor(d, mapparams) {
|
function getColor(d, mapparams) {
|
||||||
if(sysparams.category === 'laerm') {
|
if(sysparams.category === 'noise') {
|
||||||
return mapn.getColor(d, mapparams)
|
return mapn.getColor(d, mapparams)
|
||||||
} else if(sysparams.category === 'multigeiger') {
|
} else if(sysparams.category === 'multigeiger') {
|
||||||
return mapg.getColor(d, mapparams)
|
return mapg.getColor(d, mapparams)
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export async function showChart(params, typ, container) {
|
|||||||
return this.axis.defaultLabelFormatter.call(this);
|
return this.axis.defaultLabelFormatter.call(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let url = `/api/getsensordata?sensorid=${params.sid}&data=${typ}&datetime=${params.datetime}`
|
let url = `/srv/getsensordata?sensorid=${params.sid}&data=${typ}&datetime=${params.datetime}`
|
||||||
if (typ === 'live') {
|
if (typ === 'live') {
|
||||||
url += `&span=${params.span}`
|
url += `&span=${params.span}`
|
||||||
} else if ((typ === 'havg') || (typ === 'davg')) {
|
} else if ((typ === 'havg') || (typ === 'davg')) {
|
||||||
@@ -63,7 +63,7 @@ export async function showChart(params, typ, container) {
|
|||||||
}
|
}
|
||||||
let erg = await fetchfromserver(url)
|
let erg = await fetchfromserver(url)
|
||||||
if (!erg.err) {
|
if (!erg.err) {
|
||||||
if(sysparams.category === 'laerm') {
|
if(sysparams.category === 'noise') {
|
||||||
utils.showTabs()
|
utils.showTabs()
|
||||||
}
|
}
|
||||||
document.querySelector('#odth').style.display = 'none'
|
document.querySelector('#odth').style.display = 'none'
|
||||||
|
|||||||
+11
-5
@@ -21,12 +21,13 @@ let APIHOST = process.env.APIHOST || 'http://localhost:3005'
|
|||||||
/* GET home page. */
|
/* GET home page. */
|
||||||
router.get('/:cmd', async function(req, res, next) {
|
router.get('/:cmd', async function(req, res, next) {
|
||||||
// req.i18n.changeLanguage(req.query.lng)
|
// req.i18n.changeLanguage(req.query.lng)
|
||||||
|
const calledAs = req.baseUrl
|
||||||
const cmd = req.params.cmd
|
const cmd = req.params.cmd
|
||||||
|
const pretty = (req.query.pretty !== undefined)
|
||||||
const lng = getLanguage()
|
const lng = getLanguage()
|
||||||
let url = APIHOST
|
let url = APIHOST + '/api' + req.originalUrl.slice(4) + `&lng=${lng}`
|
||||||
url += (req.originalUrl + `&lng=${lng}`)
|
|
||||||
try {
|
try {
|
||||||
const response = await axios(encodeURI(url));
|
const response = await axios.get(encodeURI(url));
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
res.json({err: `${trans('ESYSCALL')} status=${response.status}`})
|
res.json({err: `${trans('ESYSCALL')} status=${response.status}`})
|
||||||
}
|
}
|
||||||
@@ -34,9 +35,14 @@ router.get('/:cmd', async function(req, res, next) {
|
|||||||
res.json(response.data)
|
res.json(response.data)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ((cmd === 'getoneproperty') || (cmd === 'getaddress')) {
|
// if called as '/api' then directly return the data
|
||||||
|
if ((calledAs === '/api') || (cmd === 'getoneproperty') || (cmd === 'getaddress')) {
|
||||||
|
if(pretty) {
|
||||||
|
res.send(JSON.stringify(response.data,null,2))
|
||||||
|
} else {
|
||||||
res.json(response.data)
|
res.json(response.data)
|
||||||
return
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
const options = response.data.options
|
const options = response.data.options
|
||||||
for(let x of disttable) {
|
for(let x of disttable) {
|
||||||
|
|||||||
+3
-3
@@ -9,8 +9,8 @@ const renderOpts = (sid, cat) => {
|
|||||||
let tit = 'Feinstaub'
|
let tit = 'Feinstaub'
|
||||||
if(cat === 'multigeiger') {
|
if(cat === 'multigeiger') {
|
||||||
tit = 'Geiger'
|
tit = 'Geiger'
|
||||||
} else if (cat == 'laerm') {
|
} else if (cat == 'noise') {
|
||||||
tit = 'Lärm'
|
tit = 'Noise'
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
title: tit,
|
title: tit,
|
||||||
@@ -28,7 +28,7 @@ const translate = (x) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getIndex = (cat) => {
|
const getIndex = (cat) => {
|
||||||
if (cat === 'laerm') {
|
if (cat == 'noise'){
|
||||||
return 'index_noise'
|
return 'index_noise'
|
||||||
} else if (cat === 'multigeiger') {
|
} else if (cat === 'multigeiger') {
|
||||||
return 'index_geiger'
|
return 'index_geiger'
|
||||||
|
|||||||
Reference in New Issue
Block a user