27 Commits

Author SHA1 Message Date
4d91fc0233 Merge branch 'release/v1.2.0'
All checks were successful
continuous-integration/drone/push Build is passing
2023-05-01 17:18:26 +02:00
4c1a7a5a51 bump version to 1.2.0 2023-05-01 17:18:13 +02:00
4628cf1544 update drone to use other registry 2023-05-01 17:16:39 +02:00
ad89f9a6ef Merge branch 'release/v1.2.0' 2023-04-19 23:11:51 +02:00
f64b200dcc bump verison to 1.2.0 2023-04-19 23:11:39 +02:00
049f4d75b9 move config options to config file, add option to diable frontend 2023-04-19 23:09:38 +02:00
dc3a682a77 documentation on environment variables
All checks were successful
continuous-integration/drone Build is passing
continuous-integration/drone/push Build is passing
2023-04-19 22:29:09 +02:00
5bcd588b0f auto formatting 2023-04-19 22:25:38 +02:00
1f8979cee8 Merge branch 'gh-main' into develop 2023-04-19 22:25:20 +02:00
Fionn
d093c016c9 Merge pull request #2 from cleboo/main
Make 'trust proxy' option configurable
2023-04-19 22:21:52 +02:00
Clemens Moritz
c87e8ee70b Make trust proxy option configurable
trust proxy option is now configurable via the TRUST_PROXY_IP
environment variable.
2023-04-18 21:45:55 +02:00
1c9c485ca4 Merge tag 'v1.1.0' into develop 2023-04-15 17:02:58 +02:00
d8432315d5 Merge branch 'release/v1.1.0'
All checks were successful
continuous-integration/drone/push Build is passing
2023-04-15 17:02:57 +02:00
7cd8ea9d50 bump version to 1.1.0 2023-04-15 17:02:40 +02:00
Fionn
80c961da81 Merge pull request #1 from MorpheusXAUT/configurable-base-path
Configurable base API path
2023-04-15 17:00:04 +02:00
Nick 'MorpheusXAUT' Müller
79e559a723 Fix Docker image URL in README 2023-03-25 17:34:37 +01:00
Nick 'MorpheusXAUT' Müller
80a354b456 Fix node_modules exclusion in dockerignore 2023-03-25 17:23:45 +01:00
Nick 'MorpheusXAUT' Müller
407f817c8d Add interrupt signal handling for graceful server shutdown 2023-03-25 17:23:15 +01:00
Nick 'MorpheusXAUT' Müller
759e4c3711 Make base API path configurable via env variable 2023-03-25 17:20:33 +01:00
8460445381 Merge branch 'release/v1.0.0' 2023-03-11 15:16:51 +01:00
131acbf75c Merge tag 'v1.0.0' into develop 2023-03-11 15:16:51 +01:00
627a39c02e remove LOVV test data, add EDXX data 2023-03-11 15:05:22 +01:00
248ac6620a add utility script for converting csv points to json 2023-03-11 15:05:05 +01:00
37db228cdd fix typo 2023-03-11 15:04:48 +01:00
2d7d2f5b5c typos 2023-03-10 21:51:30 +01:00
cd77081009 fix name, remove useless stuff from docker-compose, readme 2023-03-10 21:41:48 +01:00
b9a91a59a2 add legal note 2023-03-10 21:30:02 +01:00
13 changed files with 599 additions and 73 deletions

View File

@@ -1,2 +1,2 @@
.git .git
node_modules **/node_modules

View File

@@ -3,12 +3,12 @@ type: docker
name: build dev name: build dev
steps: steps:
- name: build and push image - name: build for staging
image: plugins/docker image: plugins/docker
settings: settings:
dockerfile: Dockerfile dockerfile: Dockerfile
registry: git.fsisp.de registry: hub.fsisp.de
repo: git.fsisp.de/fionn/isasure-wx repo: hub.fsisp.de/library/iassure-wx
username: username:
from_secret: reg_username from_secret: reg_username
password: password:
@@ -16,32 +16,27 @@ steps:
tags: tags:
- dev - dev
- '${DRONE_COMMIT:0:8}' - '${DRONE_COMMIT:0:8}'
when:
trigger:
branch: branch:
- dev - dev
- develop - develop
event:
- push
--- - name: build for production
kind: pipeline
type: docker
name: build master
steps:
- name: build and push image
image: plugins/docker image: plugins/docker
settings: settings:
dockerfile: Dockerfile dockerfile: Dockerfile
registry: git.fsisp.de registry: hub.fsisp.de
repo: git.fsisp.de/fionn/isasure-wx repo: hub.fsisp.de/library/iassure-wx
username: username:
from_secret: reg_username from_secret: reg_username
password: password:
from_secret: reg_password from_secret: reg_password
tags: tags:
- latest - latest
- '${DRONE_TAG}'
- '${DRONE_COMMIT:0:8}' - '${DRONE_COMMIT:0:8}'
when:
trigger: event:
branch: - tag
- main

View File

@@ -1,7 +1,34 @@
# TypeScript Project Template # IASsure-WX
## preparation ## idea
```sh This service is designed to gather weather data to be used by [IASsure](https://github.com/MorpheusXAUT/IASsure) by [MorpheusXAUT](https://github.com/MorpheusXAUT). It uses the [Open-Meteo.com](https://open-meteo.com)-API to gather the necessary data to provide to the plugin.
npm install -g eslint eslint-config-airbnb-typescript eslint-plugin-import eslint-plugin-n eslint-plugin-promise
## Installation/Deployment
IASsure-WX can be installed using docker. The image is available at `hub.fsisp.de/library/iassure-wx`.
Tags:
- `latest` - The newest recommended build, built from `main`
- `dev` - The newest development/staging build, built from `develop`
- Other than those tags, every image is tagged with the git commit id
## Configuration
IASsure-WX can be configured using the `wx-config.json`-file. For now it contains test data but will include production data for at least the Langen FIR. It necessary, another file can be mounted on top of it (`/opt/wx-config.json`). You may also choose to make the necessary changes to the file in this repository. The file is documented in the schema definition file (`wx-config.schema.json`).
## Environment Variables
Some options can be defined using environment variables:
```bash
# defines the port, the application will listen on
PORT=3000
# defines the base path used for the api
BASE_PATH=/api
# defines ips that are allowed as proxy ips
# See http://expressjs.com/en/guide/behind-proxies.html
TRUST_PROXY=
# set to true to disable /api-Endpoint. will also disable frontend.
DISABLE_DEFAULT_API_ENDPOINT=
``` ```

View File

@@ -1,6 +1,6 @@
{ {
"name": "app", "name": "app",
"version": "1.0.0", "version": "1.2.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"type": "module", "type": "module",

View File

@@ -3,19 +3,26 @@ import nodesched from 'node-schedule';
import morgan from 'morgan'; import morgan from 'morgan';
import router from './router'; import router from './router';
import wxService from './services/wx.service'; import wxService from './services/wx.service';
import appConfig from './config';
const { PORT = 3000 } = process.env;
const app = express(); const app = express();
app.set('trust proxy', true); const config = appConfig();
app.set('trust proxy', config.trustProxy);
app.use(morgan('combined')); app.use(morgan('combined'));
app.use('/api', router.router); if (config.apiBasePath) {
app.use(config.apiBasePath, router.router);
}
const frontendRoot = '/opt/frontend/dist'; if (!config.disableDefaultApiEndpoint) {
app.use(express.static(frontendRoot)); app.use('/api', router.router);
app.use((req, res) => res.sendFile(`${frontendRoot}/index.html`));
const frontendRoot = '/opt/frontend/dist';
app.use(express.static(frontendRoot));
app.use((req, res) => res.sendFile(`${frontendRoot}/index.html`));
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
app.use((err, req: Request, res: Response, next: NextFunction) => { app.use((err, req: Request, res: Response, next: NextFunction) => {
@@ -25,11 +32,26 @@ app.use((err, req: Request, res: Response, next: NextFunction) => {
res.status(500).json({ msg: 'an error occurred' }); res.status(500).json({ msg: 'an error occurred' });
}); });
nodesched.scheduleJob('regenerate data', '*/30 * * * * *', wxService.wrappedGenerateData) nodesched.scheduleJob('regenerate data', '*/30 * * * * *', wxService.wrappedGenerateData);
wxService.wrappedGenerateData(); wxService.wrappedGenerateData();
app.listen(PORT, () => { const server = app.listen(config.port, () => {
console.log( console.log(
`application is listening on port ${PORT}`, `application is listening on port ${config.port}`,
); );
}); });
function processShutdown(signal: string) {
console.log(`${signal} signal received. Shutting down.`);
server.close((err) => {
if (err) {
console.error(`Failed to shut down server gracefully: ${err}`);
process.exit(1);
}
console.log('Server closed');
process.exit(0);
});
}
['SIGTERM', 'SIGINT'].map(signal => process.on(signal, processShutdown.bind(undefined, signal)));

28
backend/src/config.ts Normal file
View File

@@ -0,0 +1,28 @@
export interface Config {
port: number;
apiBasePath: string;
disableDefaultApiEndpoint: boolean;
trustProxy: string | boolean;
}
export default function appConfig(): Config {
const {
PORT,
BASE_PATH,
TRUST_PROXY,
DISABLE_DEFAULT_API_ENDPOINT,
} = process.env;
let trustProxy: string | boolean = false;
if (TRUST_PROXY == '*') {
trustProxy = true;
}
return {
port: Number(PORT ?? 3000),
apiBasePath: BASE_PATH ?? '',
trustProxy,
disableDefaultApiEndpoint: DISABLE_DEFAULT_API_ENDPOINT == 'true',
};
}

View File

@@ -15,7 +15,7 @@ export async function getRegion(req: express.Request, res: express.Response, nex
const regionData = regionsService.getRegion(region); const regionData = regionsService.getRegion(region);
if(!regionData) { if (!regionData) {
return next(); return next();
} }

View File

@@ -23,4 +23,4 @@ export function getConfig(): WxConfig {
export default { export default {
getConfig, getConfig,
} };

View File

@@ -1,6 +1,6 @@
import configService, { WxConfig, WxRegion } from "./config.service"; import configService, { WxConfig, WxRegion } from './config.service';
export function getRegions(): WxConfig["regions"] { export function getRegions(): WxConfig['regions'] {
return configService.getConfig().regions; return configService.getConfig().regions;
} }

View File

@@ -1,8 +1,8 @@
import axios from "axios"; import axios from 'axios';
import { WxFix } from "./config.service"; import { WxFix } from './config.service';
import regionsService from "./regions.service"; import regionsService from './regions.service';
const cachedData: {[key: string]: WxData} = {}; const cachedData: { [key: string]: WxData } = {};
const qnhLevelMapping = { const qnhLevelMapping = {
200: 390, 200: 390,
@@ -12,7 +12,7 @@ const qnhLevelMapping = {
500: 180, 500: 180,
600: 140, 600: 140,
700: 100, 700: 100,
850: 50 850: 50,
}; };
const necessaryDatapoints = [ const necessaryDatapoints = [
@@ -34,10 +34,10 @@ for (const qnh of Object.keys(qnhLevelMapping)) {
} }
interface WxLevelData { interface WxLevelData {
"T(K)": string; 'T(K)': string;
windspeed: string; windspeed: string;
windhdg: string; windhdg: string;
}; }
export interface WxFixData { export interface WxFixData {
coords: { coords: {
@@ -54,6 +54,7 @@ export interface WxData {
info: { info: {
date: string; date: string;
datestring: string; datestring: string;
legal: string;
}; };
data: { data: {
[key: string]: WxFixData; [key: string]: WxFixData;
@@ -67,27 +68,27 @@ export async function getDataAtFix(fix: WxFix, index: number): Promise<WxFixData
const data: WxFixData = { const data: WxFixData = {
coords: { coords: {
lat: String(fix.lat), lat: String(fix.lat),
long: String(fix.lon) long: String(fix.lon),
}, },
levels: {} levels: {},
}
data.levels["0"] = {
"T(K)": String(Number(hourlyData?.[`temperature_2m`]?.[index]) + 273.15),
"windspeed": String(hourlyData?.[`windspeed_10m`]?.[index]),
"windhdg": String(hourlyData?.[`winddirection_10m`]?.[index]),
}; };
for(const [qnh, fl] of Object.entries(qnhLevelMapping)) { data.levels['0'] = {
'T(K)': String(Number(hourlyData?.temperature_2m?.[index]) + 273.15),
'windspeed': String(hourlyData?.windspeed_10m?.[index]),
'windhdg': String(hourlyData?.winddirection_10m?.[index]),
};
for (const [qnh, fl] of Object.entries(qnhLevelMapping)) {
const temp = Number(hourlyData?.[`temperature_${qnh}hPa`]?.[index]) + 273.15; const temp = Number(hourlyData?.[`temperature_${qnh}hPa`]?.[index]) + 273.15;
const dir = hourlyData?.[`winddirection_${qnh}hPa`]?.[index]; const dir = hourlyData?.[`winddirection_${qnh}hPa`]?.[index];
const speed = hourlyData?.[`windspeed_${qnh}hPa`]?.[index]; const speed = hourlyData?.[`windspeed_${qnh}hPa`]?.[index];
data.levels[String(fl)] = { data.levels[String(fl)] = {
"T(K)": String(temp), 'T(K)': String(temp),
"windspeed": String(speed), 'windspeed': String(speed),
"windhdg": String(dir), 'windhdg': String(dir),
} };
} }
return data; return data;
@@ -103,9 +104,10 @@ export async function generateData() {
info: { info: {
date: now.toISOString(), date: now.toISOString(),
datestring: `${now.getUTCDate()}${now.getUTCHours()}`, datestring: `${now.getUTCDate()}${now.getUTCHours()}`,
legal: 'Weather data by Open-Meteo.com (https://open-meteo.com)',
}, },
data: {} data: {},
} };
for (const fix of region.fixes) { for (const fix of region.fixes) {
regionData.data[fix.name] = await getDataAtFix(fix, now.getUTCHours()); regionData.data[fix.name] = await getDataAtFix(fix, now.getUTCHours());
@@ -131,4 +133,4 @@ export default {
getWx, getWx,
generateData, generateData,
wrappedGenerateData, wrappedGenerateData,
} };

View File

@@ -9,10 +9,7 @@ services:
args: args:
- NODE_ENV=development - NODE_ENV=development
ports: ports:
- '3030:3030/tcp' - '3030:3000/tcp'
- '9229:9229/tcp' - '9229:9229/tcp'
volumes: volumes:
- .:/opt:delegated - .:/opt:delegated
environment:
- MONGO_URI
- PORT=3030

View File

@@ -0,0 +1,20 @@
/**
* This script can be used to convert a csv-file to the json format required by the wx-config.json
*
* the csv needs to follow the following format: <FIX>,<LAT>,<LON>
*/
const fs = require('fs');
const points = fs
.readFileSync('./fixes.csv')
.toString()
.split('\n')
.map(str => str.split(','))
.map(data => ({
name: data[0],
lat: Number(data[1]),
lon: Number(data[2]),
}));
fs.writeFileSync('./fixes.json', JSON.stringify(points, undefined, 2));

View File

@@ -32,17 +32,452 @@
] ]
}, },
{ {
"identifier": "LOVV", "identifier": "EDXX",
"fixes": [ "fixes": [
{
"name": "RDG",
"lat": 49.040139,
"lon": 12.526625
},
{
"name": "OTT",
"lat": 48.180394,
"lon": 11.816536
},
{
"name": "LNZ",
"lat": 48.229711,
"lon": 14.103156
},
{
"name": "VOZ",
"lat": 49.532328,
"lon": 14.874664
},
{
"name": "MASUR",
"lat": 48.520097,
"lon": 15.439292
},
{ {
"name": "VATET", "name": "VATET",
"lat": 47.600953, "lat": 47.600953,
"lon": 14.033119 "lon": 14.033119
}, },
{ {
"name": "LNZ", "name": "INSEL",
"lat": 48.229711, "lat": 47.155556,
"lon": 14.103156 "lon": 12.405278
},
{
"name": "TRA",
"lat": 47.6895,
"lon": 8.436972
},
{
"name": "NAXAV",
"lat": 46.463856,
"lon": 11.322183
},
{
"name": "HOC",
"lat": 47.466556,
"lon": 7.665444
},
{
"name": "LUPEN",
"lat": 48.435053,
"lon": 7.733622
},
{
"name": "LADAT",
"lat": 49.265256,
"lon": 7.839472
},
{
"name": "GTQ",
"lat": 48.986444,
"lon": 6.716222
},
{
"name": "VALEK",
"lat": 49.514444,
"lon": 5.781111
},
{
"name": "LNO",
"lat": 50.585833,
"lon": 5.710278
},
{
"name": "BUB",
"lat": 50.902333,
"lon": 4.538083
},
{
"name": "OKIDU",
"lat": 51.7894,
"lon": 4.85
},
{
"name": "SPY",
"lat": 52.540278,
"lon": 4.853778
},
{
"name": "NAPRO",
"lat": 51.855833,
"lon": 6.058889
},
{
"name": "RKN",
"lat": 52.133194,
"lon": 6.763889
},
{
"name": "EEL",
"lat": 53.164167,
"lon": 6.66675
},
{
"name": "EDUBU",
"lat": 54.183333,
"lon": 6.5
},
{
"name": "TIPAN",
"lat": 54.598369,
"lon": 4.398944
},
{
"name": "AMADA",
"lat": 55,
"lon": 6.35
},
{
"name": "BAVTA",
"lat": 55.603056,
"lon": 8.3
},
{
"name": "ODN",
"lat": 55.581011,
"lon": 10.652989
},
{
"name": "ERNOV",
"lat": 56.168861,
"lon": 12.573778
},
{
"name": "TIDVU",
"lat": 55.411306,
"lon": 13.557528
},
{
"name": "LUSID",
"lat": 54.916667,
"lon": 15.296111
},
{
"name": "VAVUN",
"lat": 53.475278,
"lon": 15.333056
},
{
"name": "DENKO",
"lat": 52.816861,
"lon": 15.8325
},
{
"name": "KELOD",
"lat": 52.233889,
"lon": 15.883333
},
{
"name": "VELAB",
"lat": 51.469722,
"lon": 16.748889
},
{
"name": "LAGAR",
"lat": 50.795275,
"lon": 15.367089
},
{
"name": "ELMEK",
"lat": 49.9039,
"lon": 14.029875
},
{
"name": "BRENO",
"lat": 46.98,
"lon": 11.376667
},
{
"name": "ALG",
"lat": 47.997381,
"lon": 10.262189
},
{
"name": "LBU",
"lat": 48.912975,
"lon": 9.340228
},
{
"name": "DKB",
"lat": 49.142753,
"lon": 10.238306
},
{
"name": "SULUS",
"lat": 50.075192,
"lon": 10.728808
},
{
"name": "BAMKI",
"lat": 50.718064,
"lon": 11.020208
},
{
"name": "KOJEC",
"lat": 51.512719,
"lon": 11.50445
},
{
"name": "OSKAN",
"lat": 51.460847,
"lon": 13.627669
},
{
"name": "MAREM",
"lat": 50.715467,
"lon": 13.628808
},
{
"name": "ABERU",
"lat": 50.069194,
"lon": 12.093719
},
{
"name": "LAMSI",
"lat": 48.653353,
"lon": 13.583442
},
{
"name": "SBG",
"lat": 47.967533,
"lon": 12.894072
},
{
"name": "ERKIR",
"lat": 47.537778,
"lon": 12.008889
},
{
"name": "WLD",
"lat": 48.579419,
"lon": 11.129386
},
{
"name": "UPALA",
"lat": 49.214372,
"lon": 11.221436
},
{
"name": "SUL",
"lat": 48.381586,
"lon": 8.644836
},
{
"name": "KRH",
"lat": 48.992944,
"lon": 8.584236
},
{
"name": "UMDAS",
"lat": 49.395864,
"lon": 8.824181
},
{
"name": "COSJE",
"lat": 49.717531,
"lon": 9.947
},
{
"name": "BOMBI",
"lat": 50.056667,
"lon": 8.800278
},
{
"name": "UBIDU",
"lat": 50.073333,
"lon": 7.906389
},
{
"name": "UMUPU",
"lat": 50.558611,
"lon": 7.431389
},
{
"name": "BITBU",
"lat": 49.98295,
"lon": 6.561628
},
{
"name": "NVO",
"lat": 50.822675,
"lon": 6.636533
},
{
"name": "GMH",
"lat": 51.170511,
"lon": 7.892039
},
{
"name": "DODEN",
"lat": 50.602256,
"lon": 8.09325
},
{
"name": "DEMAB",
"lat": 50.541111,
"lon": 9.955833
},
{
"name": "MAPOX",
"lat": 51.133611,
"lon": 8.813889
},
{
"name": "RIMET",
"lat": 51.333889,
"lon": 10.219444
},
{
"name": "PIROT",
"lat": 52.053431,
"lon": 9.236903
},
{
"name": "HMM",
"lat": 51.856867,
"lon": 7.708294
},
{
"name": "DIBIR",
"lat": 51.276944,
"lon": 6.124444
},
{
"name": "BASUM",
"lat": 52.771989,
"lon": 8.788539
},
{
"name": "MADOR",
"lat": 52.566667,
"lon": 9.9525
},
{
"name": "HLZ",
"lat": 52.363394,
"lon": 10.795219
},
{
"name": "MAG",
"lat": 51.994989,
"lon": 11.794306
},
{
"name": "KLF",
"lat": 52.019353,
"lon": 13.563414
},
{
"name": "KORUP",
"lat": 51.583056,
"lon": 14.738056
},
{
"name": "SUBIX",
"lat": 52.379722,
"lon": 14.585556
},
{
"name": "KETAP",
"lat": 52.927853,
"lon": 13.654947
},
{
"name": "OGBER",
"lat": 52.613889,
"lon": 12.724722
},
{
"name": "BKD",
"lat": 53.034525,
"lon": 11.546217
},
{
"name": "HAM",
"lat": 53.685575,
"lon": 10.204997
},
{
"name": "WSN",
"lat": 53.347169,
"lon": 8.874733
},
{
"name": "DHE",
"lat": 54.185686,
"lon": 7.9107
},
{
"name": "ATTUS",
"lat": 54.899722,
"lon": 8.782778
},
{
"name": "ALASA",
"lat": 54.808611,
"lon": 9.961667
},
{
"name": "BAGOS",
"lat": 54.572778,
"lon": 11.27
},
{
"name": "ROBUS",
"lat": 55.109444,
"lon": 11.719722
},
{
"name": "BANKU",
"lat": 54.795833,
"lon": 12.935278
},
{
"name": "UMSET",
"lat": 54.833056,
"lon": 14.158611
},
{
"name": "POBOX",
"lat": 54.158889,
"lon": 14.094167
},
{
"name": "FLD",
"lat": 53.762736,
"lon": 13.563136
},
{
"name": "TAGOB",
"lat": 53.734772,
"lon": 11.833056
} }
] ]
} }