Skip to content

Commit

Permalink
fix: mount healthz endpoint before router to avoid overlapping issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Nov 13, 2023
1 parent eef9c80 commit ab03284
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { sendError } from '@/errors';
import { ReasonPhrases } from 'http-status-codes';
import { json } from 'body-parser';
import cors from 'cors';
import express from 'express';
// import {IRouter} from 'express';
import helmet from 'helmet';
import { serverErrors } from './errors';
import { httpLogger, logger, uncaughtErrorLogger } from './logger';
Expand All @@ -23,7 +23,18 @@ addOpenApiRoute(app);
app.use(httpLogger);
app.use(helmet(), json(), cors());
app.use(authMiddleware);


/**
* GET /healthz
* @summary Check if the server is up and running
* @return 200 - Success - application/json
* @tags General
*/
app.get('/healthz', (_req, res) => res.json(ReasonPhrases.OK));

app.use(ENV.AUTH_API_PREFIX, router);

app.use(uncaughtErrorLogger, serverErrors);

process.on('unhandledRejection', (reason) => {
Expand All @@ -48,16 +59,4 @@ process.on('uncaughtException', (err, origin) => {
process.exit(1);
});

/**
* GET /healthz
* @summary Check if the server is up and running
* @return 200 - Success - application/json
* @tags General
*/
app.get('/healthz', (_req, res) => res.json(ReasonPhrases.OK));

app.use('/', (_req, res) => {
return sendError(res, 'bad-request');
});

export { app };

0 comments on commit ab03284

Please sign in to comment.