From 759e4c3711419eb9e241bea5d062354e7cf5ab13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20=27MorpheusXAUT=27=20M=C3=BCller?= Date: Sat, 25 Mar 2023 17:18:29 +0100 Subject: [PATCH 1/4] Make base API path configurable via env variable --- backend/src/app.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/app.ts b/backend/src/app.ts index 7675c3e..7f1c251 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -4,14 +4,14 @@ import morgan from 'morgan'; import router from './router'; import wxService from './services/wx.service'; -const { PORT = 3000 } = process.env; +const { PORT = 3000, BASE_PATH = '/api' } = process.env; const app = express(); app.set('trust proxy', true); app.use(morgan('combined')); -app.use('/api', router.router); +app.use(BASE_PATH, router.router); const frontendRoot = '/opt/frontend/dist'; app.use(express.static(frontendRoot)); From 407f817c8df37cdaac3f55f7782525fff782ba1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20=27MorpheusXAUT=27=20M=C3=BCller?= Date: Sat, 25 Mar 2023 17:23:15 +0100 Subject: [PATCH 2/4] Add interrupt signal handling for graceful server shutdown --- backend/src/app.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/backend/src/app.ts b/backend/src/app.ts index 7f1c251..a5f0d96 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -28,8 +28,24 @@ app.use((err, req: Request, res: Response, next: NextFunction) => { nodesched.scheduleJob('regenerate data', '*/30 * * * * *', wxService.wrappedGenerateData) wxService.wrappedGenerateData(); -app.listen(PORT, () => { +const server = app.listen(PORT, () => { console.log( `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')); From 80a354b4567d11dec49358e4f92ada03ba7af938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20=27MorpheusXAUT=27=20M=C3=BCller?= Date: Sat, 25 Mar 2023 17:23:45 +0100 Subject: [PATCH 3/4] Fix node_modules exclusion in dockerignore --- .dockerignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index e0ba315..69eaaee 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,2 @@ .git -node_modules \ No newline at end of file +**/node_modules \ No newline at end of file From 79e559a72365cea82f52df68ae9b727246cee8ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nick=20=27MorpheusXAUT=27=20M=C3=BCller?= Date: Sat, 25 Mar 2023 17:34:37 +0100 Subject: [PATCH 4/4] Fix Docker image URL in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9865ec5..2f93384 100644 --- a/README.md +++ b/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`. +IASsure-WX can be installed using docker. The image is available at `git.fsisp.de/fionn/iassure-wx`. Tags: - `latest` - The newest recommended build, built from `main`