mirror of
https://github.com/dotFionn/iassure-wx.git
synced 2026-03-16 04:22:56 -05:00
Compare commits
12 Commits
d8432315d5
...
v1.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d91fc0233 | |||
| 4c1a7a5a51 | |||
| 4628cf1544 | |||
| ad89f9a6ef | |||
| f64b200dcc | |||
| 049f4d75b9 | |||
| dc3a682a77 | |||
| 5bcd588b0f | |||
| 1f8979cee8 | |||
|
|
d093c016c9 | ||
|
|
c87e8ee70b | ||
| 1c9c485ca4 |
31
.drone.yml
31
.drone.yml
@@ -3,12 +3,12 @@ type: docker
|
||||
name: build dev
|
||||
|
||||
steps:
|
||||
- name: build and push image
|
||||
- name: build for staging
|
||||
image: plugins/docker
|
||||
settings:
|
||||
dockerfile: Dockerfile
|
||||
registry: git.fsisp.de
|
||||
repo: git.fsisp.de/fionn/iassure-wx
|
||||
registry: hub.fsisp.de
|
||||
repo: hub.fsisp.de/library/iassure-wx
|
||||
username:
|
||||
from_secret: reg_username
|
||||
password:
|
||||
@@ -16,32 +16,27 @@ steps:
|
||||
tags:
|
||||
- dev
|
||||
- '${DRONE_COMMIT:0:8}'
|
||||
|
||||
trigger:
|
||||
when:
|
||||
branch:
|
||||
- dev
|
||||
- develop
|
||||
event:
|
||||
- push
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: build master
|
||||
|
||||
steps:
|
||||
- name: build and push image
|
||||
- name: build for production
|
||||
image: plugins/docker
|
||||
settings:
|
||||
dockerfile: Dockerfile
|
||||
registry: git.fsisp.de
|
||||
repo: git.fsisp.de/fionn/iassure-wx
|
||||
registry: hub.fsisp.de
|
||||
repo: hub.fsisp.de/library/iassure-wx
|
||||
username:
|
||||
from_secret: reg_username
|
||||
password:
|
||||
from_secret: reg_password
|
||||
tags:
|
||||
- latest
|
||||
- '${DRONE_TAG}'
|
||||
- '${DRONE_COMMIT:0:8}'
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- main
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
|
||||
18
README.md
18
README.md
@@ -6,7 +6,7 @@ This service is designed to gather weather data to be used by [IASsure](https://
|
||||
|
||||
## Installation/Deployment
|
||||
|
||||
IASsure-WX can be installed using docker. The image is available at `git.fsisp.de/fionn/iassure-wx`.
|
||||
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`
|
||||
@@ -16,3 +16,19 @@ Tags:
|
||||
## 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=
|
||||
```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "app",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
|
||||
@@ -3,19 +3,26 @@ import nodesched from 'node-schedule';
|
||||
import morgan from 'morgan';
|
||||
import router from './router';
|
||||
import wxService from './services/wx.service';
|
||||
|
||||
const { PORT = 3000, BASE_PATH = '/api' } = process.env;
|
||||
import appConfig from './config';
|
||||
|
||||
const app = express();
|
||||
|
||||
app.set('trust proxy', true);
|
||||
const config = appConfig();
|
||||
|
||||
app.set('trust proxy', config.trustProxy);
|
||||
app.use(morgan('combined'));
|
||||
|
||||
app.use(BASE_PATH, router.router);
|
||||
if (config.apiBasePath) {
|
||||
app.use(config.apiBasePath, router.router);
|
||||
}
|
||||
|
||||
if (!config.disableDefaultApiEndpoint) {
|
||||
app.use('/api', router.router);
|
||||
|
||||
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
|
||||
app.use((err, req: Request, res: Response, next: NextFunction) => {
|
||||
@@ -25,16 +32,16 @@ app.use((err, req: Request, res: Response, next: NextFunction) => {
|
||||
res.status(500).json({ msg: 'an error occurred' });
|
||||
});
|
||||
|
||||
nodesched.scheduleJob('regenerate data', '*/30 * * * * *', wxService.wrappedGenerateData)
|
||||
nodesched.scheduleJob('regenerate data', '*/30 * * * * *', wxService.wrappedGenerateData);
|
||||
wxService.wrappedGenerateData();
|
||||
|
||||
const server = app.listen(PORT, () => {
|
||||
const server = app.listen(config.port, () => {
|
||||
console.log(
|
||||
`application is listening on port ${PORT}`,
|
||||
`application is listening on port ${config.port}`,
|
||||
);
|
||||
});
|
||||
|
||||
const shutdown = (signal: string) => {
|
||||
function processShutdown(signal: string) {
|
||||
console.log(`${signal} signal received. Shutting down.`);
|
||||
server.close((err) => {
|
||||
if (err) {
|
||||
@@ -45,7 +52,6 @@ const shutdown = (signal: string) => {
|
||||
console.log('Server closed');
|
||||
process.exit(0);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
||||
process.on('SIGINT', () => shutdown('SIGINT'));
|
||||
['SIGTERM', 'SIGINT'].map(signal => process.on(signal, processShutdown.bind(undefined, signal)));
|
||||
|
||||
28
backend/src/config.ts
Normal file
28
backend/src/config.ts
Normal 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',
|
||||
};
|
||||
}
|
||||
@@ -23,4 +23,4 @@ export function getConfig(): WxConfig {
|
||||
|
||||
export default {
|
||||
getConfig,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import axios from "axios";
|
||||
import { WxFix } from "./config.service";
|
||||
import regionsService from "./regions.service";
|
||||
import axios from 'axios';
|
||||
import { WxFix } from './config.service';
|
||||
import regionsService from './regions.service';
|
||||
|
||||
const cachedData: { [key: string]: WxData } = {};
|
||||
|
||||
@@ -12,7 +12,7 @@ const qnhLevelMapping = {
|
||||
500: 180,
|
||||
600: 140,
|
||||
700: 100,
|
||||
850: 50
|
||||
850: 50,
|
||||
};
|
||||
|
||||
const necessaryDatapoints = [
|
||||
@@ -34,10 +34,10 @@ for (const qnh of Object.keys(qnhLevelMapping)) {
|
||||
}
|
||||
|
||||
interface WxLevelData {
|
||||
"T(K)": string;
|
||||
'T(K)': string;
|
||||
windspeed: string;
|
||||
windhdg: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface WxFixData {
|
||||
coords: {
|
||||
@@ -68,15 +68,15 @@ export async function getDataAtFix(fix: WxFix, index: number): Promise<WxFixData
|
||||
const data: WxFixData = {
|
||||
coords: {
|
||||
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]),
|
||||
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)) {
|
||||
@@ -85,10 +85,10 @@ export async function getDataAtFix(fix: WxFix, index: number): Promise<WxFixData
|
||||
const speed = hourlyData?.[`windspeed_${qnh}hPa`]?.[index];
|
||||
|
||||
data.levels[String(fl)] = {
|
||||
"T(K)": String(temp),
|
||||
"windspeed": String(speed),
|
||||
"windhdg": String(dir),
|
||||
}
|
||||
'T(K)': String(temp),
|
||||
'windspeed': String(speed),
|
||||
'windhdg': String(dir),
|
||||
};
|
||||
}
|
||||
|
||||
return data;
|
||||
@@ -104,10 +104,10 @@ export async function generateData() {
|
||||
info: {
|
||||
date: now.toISOString(),
|
||||
datestring: `${now.getUTCDate()}${now.getUTCHours()}`,
|
||||
legal: "Weather data by Open-Meteo.com (https://open-meteo.com)"
|
||||
legal: 'Weather data by Open-Meteo.com (https://open-meteo.com)',
|
||||
},
|
||||
data: {}
|
||||
}
|
||||
data: {},
|
||||
};
|
||||
|
||||
for (const fix of region.fixes) {
|
||||
regionData.data[fix.name] = await getDataAtFix(fix, now.getUTCHours());
|
||||
@@ -133,4 +133,4 @@ export default {
|
||||
getWx,
|
||||
generateData,
|
||||
wrappedGenerateData,
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user