feature(backend): PORT-EnvVar wordt nu ook via envvar.ts ingelezen

This commit is contained in:
Gerald Schmittinger 2025-02-26 23:18:11 +01:00
parent 73a84fa3ef
commit ee5fe4774e
4 changed files with 4 additions and 3 deletions

View file

@ -1,4 +1,4 @@
PORT=3000 DWENGO_PORT=3000
DWENGO_DB_HOST=localhost DWENGO_DB_HOST=localhost
DWENGO_DB_PORT=5431 DWENGO_DB_PORT=5431
DWENGO_DB_USERNAME=postgres DWENGO_DB_USERNAME=postgres

View file

@ -1,8 +1,9 @@
import express, { Express, Response } from 'express'; import express, { Express, Response } from 'express';
import { initORM } from './orm.js'; import { initORM } from './orm.js';
import {EnvVars, getNumericEnvVar} from "./util/envvars.js";
const app: Express = express(); const app: Express = express();
const port: string | number = process.env.PORT || 3000; const port: string | number = getNumericEnvVar(EnvVars.Port);
// TODO Replace with Express routes // TODO Replace with Express routes
app.get('/', (_, res: Response) => { app.get('/', (_, res: Response) => {

View file

@ -4,6 +4,7 @@ const DB_PREFIX = PREFIX + 'DB_';
type EnvVar = { key: string; required?: boolean; defaultValue?: any }; type EnvVar = { key: string; required?: boolean; defaultValue?: any };
export const EnvVars: { [key: string]: EnvVar } = { export const EnvVars: { [key: string]: EnvVar } = {
Port: { key: PREFIX + "PORT", defaultValue: 3000 },
DbHost: { key: DB_PREFIX + 'HOST', required: true }, DbHost: { key: DB_PREFIX + 'HOST', required: true },
DbPort: { key: DB_PREFIX + 'PORT', defaultValue: 5432 }, DbPort: { key: DB_PREFIX + 'PORT', defaultValue: 5432 },
DbName: { key: DB_PREFIX + 'NAME', defaultValue: 'dwengo' }, DbName: { key: DB_PREFIX + 'NAME', defaultValue: 'dwengo' },

View file

@ -9,7 +9,6 @@ services:
- "5431:5432" - "5431:5432"
volumes: volumes:
- postgres_data:/var/lib/postgresql/data - postgres_data:/var/lib/postgresql/data
- ./backend/config/db/init.sql:/docker-entrypoint-initdb.d/init.sql
volumes: volumes:
postgres_data: postgres_data: