37 Commits

Author SHA1 Message Date
3eea0f1714 Merge branch 'release/1.3.1' 2023-07-28 22:04:08 +02:00
9ad8c53322 bump version to 1.3.1 2023-07-28 22:03:50 +02:00
Fionn
b89691dcd1 Merge pull request #3 from MorpheusXAUT/fix-cronjob-syntax
Fix cronjob syntax for data regeneration
2023-07-07 20:18:11 +02:00
Nick 'MorpheusXAUT' Müller
86e2d092f7 Fix cronjob syntax for data regeneration 2023-07-05 16:38:59 +02:00
872becfb3a Merge tag '1.3.0' into develop 2023-06-26 21:08:11 +02:00
94ab6ee91b Merge branch 'release/1.3.0' 2023-06-26 21:08:08 +02:00
5ec66d47ff bump version to 1.3.0 2023-06-26 21:07:50 +02:00
4ffc51abe0 add additional levels
Some checks failed
continuous-integration/drone/push Build is failing
2023-05-04 20:59:30 +02:00
e93632a3de set proxy to local container 2023-05-04 20:59:23 +02:00
12c98e595a add eslint ignore line 2023-05-04 20:53:06 +02:00
4a7f3661d6 better credit links 2023-05-04 20:52:47 +02:00
34bbb71e2f remove useless import 2023-05-04 20:52:06 +02:00
ea13b9219d remove useless comments 2023-05-04 20:51:52 +02:00
3b49dcacd8 improve modal table 2023-05-04 20:51:33 +02:00
ea86f20dbd remove useless close button in modal 2023-05-04 20:51:17 +02:00
df097ab4f6 move types to shared, add first stuff 2023-05-04 20:40:10 +02:00
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
1ed359f602 Merge tag 'v1.2.0' into develop
Some checks failed
continuous-integration/drone/push Build is failing
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
131acbf75c Merge tag 'v1.0.0' into develop 2023-03-11 15:16:51 +01:00
29 changed files with 1200 additions and 273 deletions

View File

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

View File

@@ -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

View File

@@ -1,6 +1,7 @@
{
"eslint.workingDirectories": [
"backend",
"frontend"
"frontend",
"shared"
]
}

View File

@@ -59,4 +59,4 @@ COPY --from=frontendbuild --chown=node:node /opt/frontend/dist/ /opt/frontend/di
RUN npm install --quiet --unsafe-perm --no-progress --no-audit --omit=dev
CMD node --es-module-specifier-resolution=node dist/app.js
CMD node --es-module-specifier-resolution=node dist/backend/src/app.js

View File

@@ -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`.
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=
```

View File

@@ -1,12 +1,12 @@
{
"name": "app",
"version": "1.0.0",
"version": "1.2.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "app",
"version": "1.0.0",
"version": "1.2.0",
"license": "ISC",
"dependencies": {
"axios": "^1.3.4",
@@ -25,6 +25,7 @@
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.2.5",
"eslint-plugin-promise": "^6.0.1",
"resolve-tspaths": "^0.8.8",
"rimraf": "^3.0.2",
"tsc-watch": "^5.0.3",
"typescript": "^4.7.4"
@@ -460,6 +461,15 @@
"url": "https://github.com/sponsors/epoberezkin"
}
},
"node_modules/ansi-colors": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz",
"integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==",
"dev": true,
"engines": {
"node": ">=6"
}
},
"node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
@@ -719,6 +729,15 @@
"node": ">= 0.8"
}
},
"node_modules/commander": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-10.0.0.tgz",
"integrity": "sha512-zS5PnTI22FIRM6ylNW8G4Ap0IEOyk62fhLSD0+uHRT9McRCLGpkVNvao4bjimpK/GShynyQkFFxHhwMcETmduA==",
"dev": true,
"engines": {
"node": ">=14"
}
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -2882,6 +2901,23 @@
"node": ">=4"
}
},
"node_modules/resolve-tspaths": {
"version": "0.8.13",
"resolved": "https://registry.npmjs.org/resolve-tspaths/-/resolve-tspaths-0.8.13.tgz",
"integrity": "sha512-eHlHinC2qt3jQLFiZyUE4HXZOTlT1abHO2fb+OI9Ybsn8wdhKiAtIFVy1+QVTaIQNphCLvm42EkqJt/+ZAA8Sw==",
"dev": true,
"dependencies": {
"ansi-colors": "4.1.3",
"commander": "10.0.0",
"fast-glob": "3.2.12"
},
"bin": {
"resolve-tspaths": "dist/main.js"
},
"peerDependencies": {
"typescript": ">=3.0.3"
}
},
"node_modules/reusify": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz",
@@ -3765,6 +3801,12 @@
"uri-js": "^4.2.2"
}
},
"ansi-colors": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz",
"integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==",
"dev": true
},
"ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
@@ -3973,6 +4015,12 @@
"delayed-stream": "~1.0.0"
}
},
"commander": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-10.0.0.tgz",
"integrity": "sha512-zS5PnTI22FIRM6ylNW8G4Ap0IEOyk62fhLSD0+uHRT9McRCLGpkVNvao4bjimpK/GShynyQkFFxHhwMcETmduA==",
"dev": true
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -5564,6 +5612,17 @@
"integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==",
"dev": true
},
"resolve-tspaths": {
"version": "0.8.13",
"resolved": "https://registry.npmjs.org/resolve-tspaths/-/resolve-tspaths-0.8.13.tgz",
"integrity": "sha512-eHlHinC2qt3jQLFiZyUE4HXZOTlT1abHO2fb+OI9Ybsn8wdhKiAtIFVy1+QVTaIQNphCLvm42EkqJt/+ZAA8Sw==",
"dev": true,
"requires": {
"ansi-colors": "4.1.3",
"commander": "10.0.0",
"fast-glob": "3.2.12"
}
},
"reusify": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz",

View File

@@ -1,13 +1,14 @@
{
"name": "app",
"version": "1.0.0",
"version": "1.3.1",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"predev": "npm install && rimraf dist/*",
"start": "node --inspect=0.0.0.0:9229 --es-module-specifier-resolution=node dist/app.js",
"prestart": "resolve-tspaths --out \"/opt/backend/dist/backend/src\"",
"start": "node --inspect=0.0.0.0:9229 dist/backend/src/app.js",
"dev": "tsc-watch --onSuccess \"npm run start\" --onFailure \"echo WHOOPS! Server compilation failed\""
},
"keywords": [],
@@ -32,6 +33,7 @@
"eslint-plugin-promise": "^6.0.1",
"rimraf": "^3.0.2",
"tsc-watch": "^5.0.3",
"resolve-tspaths": "^0.8.8",
"typescript": "^4.7.4"
}
}

View File

@@ -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 } = 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('/api', router.router);
if (config.apiBasePath) {
app.use(config.apiBasePath, router.router);
}
const frontendRoot = '/opt/frontend/dist';
app.use(express.static(frontendRoot));
app.use((req, res) => res.sendFile(`${frontendRoot}/index.html`));
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,11 +32,26 @@ 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();
app.listen(PORT, () => {
const server = app.listen(config.port, () => {
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);
if(!regionData) {
if (!regionData) {
return next();
}

View File

@@ -1,19 +1,6 @@
import fs from 'fs';
import { WxConfig } from '@shared/types/config.types';
export interface WxConfig {
regions: WxRegion[];
}
export interface WxRegion {
identifier: string;
fixes: WxFix[];
}
export interface WxFix {
name: string;
lat: number;
lon: number;
}
export function getConfig(): WxConfig {
const data = JSON.parse(fs.readFileSync('/opt/wx-config.json').toString());
@@ -23,4 +10,4 @@ export function getConfig(): WxConfig {
export default {
getConfig,
}
};

View File

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

View File

@@ -1,8 +1,10 @@
import axios from "axios";
import { WxFix } from "./config.service";
import regionsService from "./regions.service";
import axios from 'axios';
import regionsService from './regions.service';
const cachedData: {[key: string]: WxData} = {};
import { WxFix } from '@shared/types/config.types';
import { WxFixData, WxData } from '@shared/types/wx.types';
const cachedData: { [key: string]: WxData } = {};
const qnhLevelMapping = {
200: 390,
@@ -12,7 +14,10 @@ const qnhLevelMapping = {
500: 180,
600: 140,
700: 100,
850: 50
800: 64,
850: 50,
900: 30,
925: 25,
};
const necessaryDatapoints = [
@@ -33,34 +38,6 @@ for (const qnh of Object.keys(qnhLevelMapping)) {
}
}
interface WxLevelData {
"T(K)": string;
windspeed: string;
windhdg: string;
};
export interface WxFixData {
coords: {
lat: string;
long: string;
};
levels: {
[key: string]: WxLevelData;
}
}
export interface WxData {
info: {
date: string;
datestring: string;
legal: string;
};
data: {
[key: string]: WxFixData;
}
}
export async function getDataAtFix(fix: WxFix, index: number): Promise<WxFixData> {
const response = await axios.get(`https://api.open-meteo.com/v1/forecast?latitude=${fix.lat}&longitude=${fix.lon}&windspeed_unit=kn&forecast_days=1&hourly=${requestedData.join(',')}`);
const hourlyData = response.data.hourly;
@@ -68,27 +45,27 @@ 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: {}
}
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]),
levels: {},
};
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 dir = hourlyData?.[`winddirection_${qnh}hPa`]?.[index];
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 +81,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 +110,4 @@ export default {
getWx,
generateData,
wrappedGenerateData,
}
};

View File

@@ -2,6 +2,7 @@
"compileOnSave": false,
"compilerOptions": {
"outDir": "dist",
"baseUrl": "./src",
"module": "ES2022",
"target": "ES2022",
"lib": [
@@ -15,6 +16,9 @@
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"moduleResolution": "Node",
"paths": {
"@shared/*": ["../../shared/src/*"]
}
},
"watchOptions": {
"watchFile": "fixedpollinginterval"

View File

@@ -28,5 +28,8 @@
"error",
"always"
]
}
},
"ignorePatterns": [
"**/vite.config.ts"
]
}

View File

@@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<title>IASsure-WX</title>
</head>
<body>
<div id="root"></div>

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
{
"name": "frontend",
"private": true,
"version": "0.0.0",
"version": "1.3.1",
"type": "module",
"scripts": {
"dev": "vite",
@@ -9,10 +9,18 @@
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.4.0",
"bootstrap": "^5.2.3",
"leaflet": "^1.9.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-bootstrap": "^2.7.4",
"react-dom": "^18.2.0",
"react-leaflet": "^4.2.1",
"react-router": "^6.11.1"
},
"devDependencies": {
"@types/leaflet": "^1.9.3",
"@types/node": "^18.16.3",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9",
"@typescript-eslint/eslint-plugin": "^5.38.1",

View File

@@ -1,41 +0,0 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
}

View File

@@ -1,33 +1,162 @@
import { useState } from 'react';
import reactLogo from './assets/react.svg';
import './App.css';
import 'leaflet/dist/leaflet.css';
import 'bootstrap/dist/css/bootstrap.css';
import { MapContainer, TileLayer, LayersControl, LayerGroup, Popup, Marker } from 'react-leaflet';
import { Button, Modal, Table } from 'react-bootstrap';
import { useEffect, useState } from 'react';
import wxService from './services/wx.service';
import { WxRegion } from '@shared/types/config.types';
import { WxData } from '../../shared/src/types/wx.types';
import { DivIcon } from 'leaflet';
function App() {
const [count, setCount] = useState(0);
const [showModal, setShowModal] = useState(false);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [loading, setLoading] = useState(false);
const [regions, setRegions] = useState<WxRegion[]>([]);
const [selectedRegion, setSelectedRegion] = useState<string>('');
const [wxData, setWxData] = useState<WxData | null>(null);
function getSetShowModal(val: boolean) {
return () => setShowModal(val);
}
useEffect(() => {
if (selectedRegion) {
return;
}
setLoading(true);
wxService.getRegions()
.then(regionsResponse => {
setRegions(regionsResponse);
setShowModal(true);
setLoading(false);
});
}, []);
useEffect(() => {
setLoading(true);
wxService.getWxData(selectedRegion).then(wxResponse => {
setWxData(wxResponse);
setShowModal(false);
setLoading(false);
console.log(wxResponse);
});
}, [selectedRegion]);
return (
<div className="App">
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" className="logo" alt="Vite logo" />
</a>
<a href="https://reactjs.org" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount(count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
<>
<Modal
show={showModal}
backdrop="static"
keyboard={false}
>
<Modal.Header>
<Modal.Title>Regions</Modal.Title>
</Modal.Header>
<Modal.Body>
<Table striped>
<thead>
<tr>
<th>#</th>
<th>Region</th>
<th>Fixes</th>
<th></th>
</tr>
</thead>
<tbody>
{regions.length ? regions.map((region, idx) => <>
<tr key={idx}>
<td>{idx + 1}</td>
<td>{region.identifier}</td>
<td>{region.fixes.length} Fixes</td>
<td>
<Button
variant={selectedRegion == region.identifier ? 'success' : 'primary'}
type='button'
onClick={() => setSelectedRegion(region.identifier)}
>
Select
</Button>
</td>
</tr>
</>) : (<>
<tr>
<td className='p-2 text-center' colSpan={4}>- no regions defined -</td>
</tr>
</>)}
</tbody>
</Table>
</Modal.Body>
</Modal>
<div className='position-absolute bottom-0 p-2' style={{ zIndex: 999 }}>
<Button variant='outline-secondary' type='button' onClick={getSetShowModal(true)}> {selectedRegion && `(Selected: ${selectedRegion})`}</Button>
</div>
<MapContainer style={{ height: '100vh', width: '100vw' }} center={[50.033306, 8.570456]} zoom={7} scrollWheelZoom={true}>
<TileLayer
url='https://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}.png'
attribution={[
'<a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>',
'<a href="https://carto.com/attributions" target="_blank">CARTO</a>',
'Weather data by Open-Meteo.com (<a href="https://open-meteo.com" target="_blank">open-meteo.com</a>)',
'<a href="https://github.com/dotFionn/iassure-wx" target="_blank">IASsure-WX</a>: <a href="https://fsperath.de" target="_blank">Fionn Sperath</a> and <a href="https://github.com/dotFionn/iassure-wx/graphs/contributors" target="_blank">contributors</a>',
].map(str => `&copy; ${str}`).join(' | ')}
subdomains={'abc'}
maxZoom={20}
minZoom={0}
/>
<LayersControl position='topright'>
<LayersControl.Overlay checked name='Enable labels'>
<TileLayer
url='https://{s}.basemaps.cartocdn.com/dark_only_labels/{z}/{x}/{y}.png'
subdomains={'abc'}
maxZoom={20}
minZoom={0}
/>
</LayersControl.Overlay>
<LayersControl.Overlay checked name="Points">
<LayerGroup>
{Object.entries(wxData?.data || {}).map(([fix, data]) => (
<>
<Marker
position={[Number(data.coords.lat), Number(data.coords.long)]}
key={fix}
title={fix}
icon={new DivIcon({ html: `⨀&nbsp;<span class="fw-bold">${fix}</span>`, className: 'bg-none text-warning' })}
>
<Popup>
<Table>
<thead>
<tr><th colSpan={3} className='text-center'>{fix}</th></tr>
<tr><th>Lvl</th><th>Temp/K</th><th>Wind</th></tr>
</thead>
<tbody>
{Object.entries(data.levels).map(([lvl, lvlData], lvlIdx) => (
<tr key={lvlIdx}>
<td>{lvl}</td>
<td>{Math.round(Number(lvlData['T(K)']))}</td>
<td>{lvlData.windhdg}° / {lvlData.windspeed}kts</td>
</tr>
))}
</tbody>
</Table>
</Popup>
</Marker>
</>
))}
</LayerGroup>
</LayersControl.Overlay>
</LayersControl>
</MapContainer>
</>
);
}

View File

@@ -1,70 +1,6 @@
:root {
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 24px;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
height: 100vh;
width: 100vw;
overflow: hidden;
}

View File

@@ -0,0 +1,18 @@
import { WxRegion } from '@shared/types/config.types';
import { WxData } from '@shared/types/wx.types';
import axios from 'axios';
async function getRegions(): Promise<WxRegion[]> {
const response = await axios.get<WxRegion[]>('/api/regions');
return response.data;
}
async function getWxData(region: string): Promise<WxData> {
const response = await axios.get<WxData>(`/api/regions/${region}/wx`);
return response.data;
}
export default {
getRegions,
getWxData,
};

View File

@@ -14,7 +14,10 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "react-jsx",
"paths": {
"@shared/*": ["../shared/src/*"]
}
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]

View File

@@ -1,7 +1,21 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import * as path from 'path';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})
resolve: {
alias: [{ find: '@shared', replacement: path.resolve(__dirname, '..', 'shared', 'src') }],
},
server: {
proxy: {
'/api': {
target: 'http://localhost:3030',
changeOrigin: true,
// secure: false,
// ws: true,
},
},
},
});

31
shared/.eslintrc.json Normal file
View File

@@ -0,0 +1,31 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": [
"airbnb-typescript/base",
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"import",
"promise"
],
"overrides": [],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"eol-last": [
"error",
"always"
]
}
}

10
shared/package.json Normal file
View File

@@ -0,0 +1,10 @@
{
"devDependencies": {
"@types/node": "^18.6.2",
"eslint": "^8.23.1",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.2.5",
"eslint-plugin-promise": "^6.0.1"
}
}

View File

@@ -0,0 +1,14 @@
export interface WxConfig {
regions: WxRegion[];
}
export interface WxRegion {
identifier: string;
fixes: WxFix[];
}
export interface WxFix {
name: string;
lat: number;
lon: number;
}

View File

@@ -0,0 +1,27 @@
export interface WxLevelData {
'T(K)': string;
windspeed: string;
windhdg: string;
}
export interface WxFixData {
coords: {
lat: string;
long: string;
};
levels: {
[key: string]: WxLevelData;
}
}
export interface WxData {
info: {
date: string;
datestring: string;
legal: string;
};
data: {
[key: string]: WxFixData;
}
}

16
shared/tsconfig.json Normal file
View File

@@ -0,0 +1,16 @@
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "dist",
"baseUrl": "./src",
"module": "ES2022",
"target": "ES2022",
"lib": ["ES2022"],
"sourceMap": true,
"strictNullChecks": true,
"noImplicitAny": false,
"preserveConstEnums": true,
"removeComments": true,
"forceConsistentCasingInFileNames": true
}
}