mirror of
https://github.com/dotFionn/iassure-wx.git
synced 2026-03-16 04:22:56 -05:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 94ab6ee91b | |||
| 5ec66d47ff | |||
| 4ffc51abe0 | |||
| e93632a3de | |||
| 12c98e595a | |||
| 4a7f3661d6 | |||
| 34bbb71e2f | |||
| ea13b9219d | |||
| 3b49dcacd8 | |||
| ea86f20dbd | |||
| df097ab4f6 | |||
| 4d91fc0233 | |||
| 1ed359f602 | |||
| 4c1a7a5a51 | |||
| 4628cf1544 | |||
| ad89f9a6ef | |||
| f64b200dcc | |||
| 049f4d75b9 | |||
| dc3a682a77 | |||
| 5bcd588b0f | |||
| 1f8979cee8 | |||
|
|
d093c016c9 | ||
|
|
c87e8ee70b | ||
| 1c9c485ca4 |
37
.drone.yml
37
.drone.yml
@@ -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/iassure-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:
|
||||||
|
branch:
|
||||||
|
- dev
|
||||||
|
- develop
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
|
||||||
trigger:
|
- name: build for production
|
||||||
branch:
|
|
||||||
- dev
|
|
||||||
- develop
|
|
||||||
|
|
||||||
---
|
|
||||||
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/iassure-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
|
|
||||||
|
|||||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"eslint.workingDirectories": [
|
"eslint.workingDirectories": [
|
||||||
"backend",
|
"backend",
|
||||||
"frontend"
|
"frontend",
|
||||||
|
"shared"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -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
|
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
|
||||||
|
|||||||
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
|
## 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:
|
Tags:
|
||||||
- `latest` - The newest recommended build, built from `main`
|
- `latest` - The newest recommended build, built from `main`
|
||||||
@@ -16,3 +16,19 @@ 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=
|
||||||
|
# set to true to disable /api-Endpoint. will also disable frontend.
|
||||||
|
DISABLE_DEFAULT_API_ENDPOINT=
|
||||||
|
```
|
||||||
|
|||||||
63
backend/package-lock.json
generated
63
backend/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "app",
|
"name": "app",
|
||||||
"version": "1.0.0",
|
"version": "1.2.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "app",
|
"name": "app",
|
||||||
"version": "1.0.0",
|
"version": "1.2.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.3.4",
|
"axios": "^1.3.4",
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
"eslint-plugin-import": "^2.26.0",
|
"eslint-plugin-import": "^2.26.0",
|
||||||
"eslint-plugin-n": "^15.2.5",
|
"eslint-plugin-n": "^15.2.5",
|
||||||
"eslint-plugin-promise": "^6.0.1",
|
"eslint-plugin-promise": "^6.0.1",
|
||||||
|
"resolve-tspaths": "^0.8.8",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"tsc-watch": "^5.0.3",
|
"tsc-watch": "^5.0.3",
|
||||||
"typescript": "^4.7.4"
|
"typescript": "^4.7.4"
|
||||||
@@ -460,6 +461,15 @@
|
|||||||
"url": "https://github.com/sponsors/epoberezkin"
|
"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": {
|
"node_modules/ansi-regex": {
|
||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
||||||
@@ -719,6 +729,15 @@
|
|||||||
"node": ">= 0.8"
|
"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": {
|
"node_modules/concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
@@ -2882,6 +2901,23 @@
|
|||||||
"node": ">=4"
|
"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": {
|
"node_modules/reusify": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz",
|
||||||
@@ -3765,6 +3801,12 @@
|
|||||||
"uri-js": "^4.2.2"
|
"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": {
|
"ansi-regex": {
|
||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
||||||
@@ -3973,6 +4015,12 @@
|
|||||||
"delayed-stream": "~1.0.0"
|
"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": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
@@ -5564,6 +5612,17 @@
|
|||||||
"integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==",
|
"integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==",
|
||||||
"dev": true
|
"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": {
|
"reusify": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz",
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "app",
|
"name": "app",
|
||||||
"version": "1.1.0",
|
"version": "1.3.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"predev": "npm install && rimraf dist/*",
|
"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\""
|
"dev": "tsc-watch --onSuccess \"npm run start\" --onFailure \"echo WHOOPS! Server compilation failed\""
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
@@ -32,6 +33,7 @@
|
|||||||
"eslint-plugin-promise": "^6.0.1",
|
"eslint-plugin-promise": "^6.0.1",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"tsc-watch": "^5.0.3",
|
"tsc-watch": "^5.0.3",
|
||||||
|
"resolve-tspaths": "^0.8.8",
|
||||||
"typescript": "^4.7.4"
|
"typescript": "^4.7.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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, BASE_PATH = '/api' } = 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(BASE_PATH, 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,16 +32,16 @@ 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();
|
||||||
|
|
||||||
const server = 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}`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const shutdown = (signal: string) => {
|
function processShutdown(signal: string) {
|
||||||
console.log(`${signal} signal received. Shutting down.`);
|
console.log(`${signal} signal received. Shutting down.`);
|
||||||
server.close((err) => {
|
server.close((err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -45,7 +52,6 @@ const shutdown = (signal: string) => {
|
|||||||
console.log('Server closed');
|
console.log('Server closed');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
['SIGTERM', 'SIGINT'].map(signal => process.on(signal, processShutdown.bind(undefined, signal)));
|
||||||
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
||||||
|
|||||||
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',
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,6 @@
|
|||||||
import fs from 'fs';
|
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 {
|
export function getConfig(): WxConfig {
|
||||||
const data = JSON.parse(fs.readFileSync('/opt/wx-config.json').toString());
|
const data = JSON.parse(fs.readFileSync('/opt/wx-config.json').toString());
|
||||||
@@ -23,4 +10,4 @@ export function getConfig(): WxConfig {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
getConfig,
|
getConfig,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -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;
|
return configService.getConfig().regions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import axios from "axios";
|
import axios from 'axios';
|
||||||
import { WxFix } from "./config.service";
|
import regionsService from './regions.service';
|
||||||
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 = {
|
const qnhLevelMapping = {
|
||||||
200: 390,
|
200: 390,
|
||||||
@@ -12,7 +14,10 @@ const qnhLevelMapping = {
|
|||||||
500: 180,
|
500: 180,
|
||||||
600: 140,
|
600: 140,
|
||||||
700: 100,
|
700: 100,
|
||||||
850: 50
|
800: 64,
|
||||||
|
850: 50,
|
||||||
|
900: 30,
|
||||||
|
925: 25,
|
||||||
};
|
};
|
||||||
|
|
||||||
const necessaryDatapoints = [
|
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> {
|
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 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;
|
const hourlyData = response.data.hourly;
|
||||||
@@ -68,27 +45,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;
|
||||||
@@ -104,10 +81,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 +110,4 @@ export default {
|
|||||||
getWx,
|
getWx,
|
||||||
generateData,
|
generateData,
|
||||||
wrappedGenerateData,
|
wrappedGenerateData,
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
"compileOnSave": false,
|
"compileOnSave": false,
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
|
"baseUrl": "./src",
|
||||||
"module": "ES2022",
|
"module": "ES2022",
|
||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"lib": [
|
"lib": [
|
||||||
@@ -15,6 +16,9 @@
|
|||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"moduleResolution": "Node",
|
"moduleResolution": "Node",
|
||||||
|
"paths": {
|
||||||
|
"@shared/*": ["../../shared/src/*"]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"watchOptions": {
|
"watchOptions": {
|
||||||
"watchFile": "fixedpollinginterval"
|
"watchFile": "fixedpollinginterval"
|
||||||
|
|||||||
@@ -28,5 +28,8 @@
|
|||||||
"error",
|
"error",
|
||||||
"always"
|
"always"
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"ignorePatterns": [
|
||||||
|
"**/vite.config.ts"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Vite + React + TS</title>
|
<title>IASsure-WX</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
|||||||
715
frontend/package-lock.json
generated
715
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "frontend",
|
"name": "frontend",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "1.3.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
@@ -9,10 +9,18 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^1.4.0",
|
||||||
|
"bootstrap": "^5.2.3",
|
||||||
|
"leaflet": "^1.9.3",
|
||||||
"react": "^18.2.0",
|
"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": {
|
"devDependencies": {
|
||||||
|
"@types/leaflet": "^1.9.3",
|
||||||
|
"@types/node": "^18.16.3",
|
||||||
"@types/react": "^18.0.26",
|
"@types/react": "^18.0.26",
|
||||||
"@types/react-dom": "^18.0.9",
|
"@types/react-dom": "^18.0.9",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.38.1",
|
"@typescript-eslint/eslint-plugin": "^5.38.1",
|
||||||
@@ -27,4 +35,4 @@
|
|||||||
"typescript": "^4.9.4",
|
"typescript": "^4.9.4",
|
||||||
"vite": "^4.0.0"
|
"vite": "^4.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -1,33 +1,162 @@
|
|||||||
import { useState } from 'react';
|
import 'leaflet/dist/leaflet.css';
|
||||||
import reactLogo from './assets/react.svg';
|
import 'bootstrap/dist/css/bootstrap.css';
|
||||||
import './App.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() {
|
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 (
|
return (
|
||||||
<div className="App">
|
<>
|
||||||
<div>
|
<Modal
|
||||||
<a href="https://vitejs.dev" target="_blank">
|
show={showModal}
|
||||||
<img src="/vite.svg" className="logo" alt="Vite logo" />
|
backdrop="static"
|
||||||
</a>
|
keyboard={false}
|
||||||
<a href="https://reactjs.org" target="_blank">
|
>
|
||||||
<img src={reactLogo} className="logo react" alt="React logo" />
|
<Modal.Header>
|
||||||
</a>
|
<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>
|
</div>
|
||||||
<h1>Vite + React</h1>
|
|
||||||
<div className="card">
|
<MapContainer style={{ height: '100vh', width: '100vw' }} center={[50.033306, 8.570456]} zoom={7} scrollWheelZoom={true}>
|
||||||
<button onClick={() => setCount(count + 1)}>
|
<TileLayer
|
||||||
count is {count}
|
url='https://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}.png'
|
||||||
</button>
|
attribution={[
|
||||||
<p>
|
'<a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>',
|
||||||
Edit <code>src/App.tsx</code> and save to test HMR
|
'<a href="https://carto.com/attributions" target="_blank">CARTO</a>',
|
||||||
</p>
|
'Weather data by Open-Meteo.com (<a href="https://open-meteo.com" target="_blank">open-meteo.com</a>)',
|
||||||
</div>
|
'<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>',
|
||||||
<p className="read-the-docs">
|
].map(str => `© ${str}`).join(' | ')}
|
||||||
Click on the Vite and React logos to learn more
|
subdomains={'abc'}
|
||||||
</p>
|
maxZoom={20}
|
||||||
</div>
|
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: `⨀ <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>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
display: flex;
|
height: 100vh;
|
||||||
place-items: center;
|
width: 100vw;
|
||||||
min-width: 320px;
|
overflow: hidden;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
18
frontend/src/services/wx.service.ts
Normal file
18
frontend/src/services/wx.service.ts
Normal 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,
|
||||||
|
};
|
||||||
@@ -14,7 +14,10 @@
|
|||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
"jsx": "react-jsx"
|
"jsx": "react-jsx",
|
||||||
|
"paths": {
|
||||||
|
"@shared/*": ["../shared/src/*"]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"include": ["src"],
|
"include": ["src"],
|
||||||
"references": [{ "path": "./tsconfig.node.json" }]
|
"references": [{ "path": "./tsconfig.node.json" }]
|
||||||
|
|||||||
@@ -1,7 +1,21 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
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
31
shared/.eslintrc.json
Normal 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
10
shared/package.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
14
shared/src/types/config.types.ts
Normal file
14
shared/src/types/config.types.ts
Normal 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;
|
||||||
|
}
|
||||||
27
shared/src/types/wx.types.ts
Normal file
27
shared/src/types/wx.types.ts
Normal 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
16
shared/tsconfig.json
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user