From 11f546acf347cf5ab48872006c15092aaccec6a7 Mon Sep 17 00:00:00 2001 From: Pascal Fong Kye Date: Thu, 18 Jul 2024 17:59:48 +0200 Subject: [PATCH] chore(api): use env var for base path url --- .env.test | 1 + README.md | 4 ++++ src/start.ts | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.env.test b/.env.test index a28e760..9e4143d 100644 --- a/.env.test +++ b/.env.test @@ -1,3 +1,4 @@ +API_BASE_PATH=/api/v1/homer GITLAB_SECRET=GITLAB_SECRET GITLAB_TOKEN=GITLAB_TOKEN NODE_ENV=test diff --git a/README.md b/README.md index a91b4a8..028f6fc 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,10 @@ Be sure to have all those installed: Create a `.env` file containing the following variables: +- `API_BASE_PATH` + + This is the base path that will be used to build the API URL to call homer, for example `https://homer.com//command`. + - `GITLAB_SECRET` This is a user generated secret, so you can put any value. diff --git a/src/start.ts b/src/start.ts index dd51048..04b2428 100644 --- a/src/start.ts +++ b/src/start.ts @@ -9,6 +9,7 @@ import { connectToDatabase } from '@/core/services/data'; import { logger } from '@/core/services/logger'; import { catchAsyncRouteErrors } from '@/core/utils/catchAsyncRouteErrors'; import { REQUEST_BODY_SIZE_LIMIT } from './constants'; +import { getEnvVariable } from './core/utils/getEnvVariable'; import { router } from './router'; const PORT = 3000; @@ -35,7 +36,7 @@ export async function start(): Promise<() => Promise> { catchAsyncRouteErrors(stateRequestHandler) ); app.use(securityMiddleware); - app.use('/api/v1/homer', router); + app.use(getEnvVariable('API_BASE_PATH'), router); app.use(errorMiddleware); const server = app.listen(PORT, async () => {