mirror of
https://github.com/dotFionn/iassure-wx.git
synced 2026-03-17 04:42:57 -05:00
Compare commits
6 Commits
dc3a682a77
...
v1.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d91fc0233 | |||
| 4c1a7a5a51 | |||
| 4628cf1544 | |||
| ad89f9a6ef | |||
| f64b200dcc | |||
| 049f4d75b9 |
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
|
|
||||||
|
|||||||
@@ -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`
|
||||||
@@ -28,5 +28,7 @@ PORT=3000
|
|||||||
BASE_PATH=/api
|
BASE_PATH=/api
|
||||||
# defines ips that are allowed as proxy ips
|
# defines ips that are allowed as proxy ips
|
||||||
# See http://expressjs.com/en/guide/behind-proxies.html
|
# See http://expressjs.com/en/guide/behind-proxies.html
|
||||||
TRUST_PROXY_ID=
|
TRUST_PROXY=
|
||||||
|
# set to true to disable /api-Endpoint. will also disable frontend.
|
||||||
|
DISABLE_DEFAULT_API_ENDPOINT=
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "app",
|
"name": "app",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -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', TRUST_PROXY_IP = false } = process.env;
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.set('trust proxy', TRUST_PROXY_IP);
|
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) => {
|
||||||
@@ -28,13 +35,13 @@ app.use((err, req: Request, res: Response, next: NextFunction) => {
|
|||||||
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',
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user