14 Commits

Author SHA1 Message Date
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
131acbf75c Merge tag 'v1.0.0' into develop 2023-03-11 15:16:51 +01:00
8 changed files with 66 additions and 36 deletions

View File

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

View File

@@ -6,7 +6,7 @@ This service is designed to gather weather data to be used by [IASsure](https://
## Installation/Deployment ## Installation/Deployment
IASsure-WX can be installed using docker. The image is available at `git.fsisp.de/fionn/iassure`. IASsure-WX can be installed using docker. The image is available at `git.fsisp.de/fionn/iassure-wx`.
Tags: Tags:
- `latest` - The newest recommended build, built from `main` - `latest` - The newest recommended build, built from `main`
@@ -16,3 +16,17 @@ Tags:
## Configuration ## 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`). 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_ID=
```

View File

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

View File

@@ -4,14 +4,14 @@ import morgan from 'morgan';
import router from './router'; import router from './router';
import wxService from './services/wx.service'; import wxService from './services/wx.service';
const { PORT = 3000 } = process.env; const { PORT = 3000, BASE_PATH = '/api', TRUST_PROXY_IP = false } = process.env;
const app = express(); const app = express();
app.set('trust proxy', true); app.set('trust proxy', TRUST_PROXY_IP);
app.use(morgan('combined')); app.use(morgan('combined'));
app.use('/api', router.router); app.use(BASE_PATH, router.router);
const frontendRoot = '/opt/frontend/dist'; const frontendRoot = '/opt/frontend/dist';
app.use(express.static(frontendRoot)); app.use(express.static(frontendRoot));
@@ -25,11 +25,27 @@ 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(PORT, () => {
console.log( console.log(
`application is listening on port ${PORT}`, `application is listening on port ${PORT}`,
); );
}); });
const shutdown = (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);
});
};
process.on('SIGTERM', () => shutdown('SIGTERM'));
process.on('SIGINT', () => shutdown('SIGINT'));

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,6 +1,6 @@
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 } = {};
@@ -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: {
@@ -68,15 +68,15 @@ 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"] = { data.levels['0'] = {
"T(K)": String(Number(hourlyData?.[`temperature_2m`]?.[index]) + 273.15), 'T(K)': String(Number(hourlyData?.temperature_2m?.[index]) + 273.15),
"windspeed": String(hourlyData?.[`windspeed_10m`]?.[index]), 'windspeed': String(hourlyData?.windspeed_10m?.[index]),
"windhdg": String(hourlyData?.[`winddirection_10m`]?.[index]), 'windhdg': String(hourlyData?.winddirection_10m?.[index]),
}; };
for (const [qnh, fl] of Object.entries(qnhLevelMapping)) { 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]; 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;
@@ -104,10 +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)" 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());
@@ -133,4 +133,4 @@ export default {
getWx, getWx,
generateData, generateData,
wrappedGenerateData, wrappedGenerateData,
} };