Skip to content

Commit

Permalink
chore(api): use env var for base path url
Browse files Browse the repository at this point in the history
  • Loading branch information
pfongkye committed Jul 18, 2024
1 parent 3989695 commit 11f546a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
API_BASE_PATH=/api/v1/homer
GITLAB_SECRET=GITLAB_SECRET
GITLAB_TOKEN=GITLAB_TOKEN
NODE_ENV=test
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<API_BASE_PATH>/command`.

- `GITLAB_SECRET`

This is a user generated secret, so you can put any value.
Expand Down
3 changes: 2 additions & 1 deletion src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,7 +36,7 @@ export async function start(): Promise<() => Promise<void>> {
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 () => {
Expand Down

0 comments on commit 11f546a

Please sign in to comment.