Skip to content

Commit

Permalink
Add status api
Browse files Browse the repository at this point in the history
  • Loading branch information
maidul98 committed Jan 6, 2023
1 parent 9386efd commit cb60151
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
8 changes: 7 additions & 1 deletion backend/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { patchRouterParam } = require('./utils/patchAsyncRoutes');

import express from 'express';
import express, { Request, Response } from 'express';
import helmet from 'helmet';
import cors from 'cors';
import cookieParser from 'cookie-parser';
Expand Down Expand Up @@ -43,6 +43,8 @@ import {
apiKeyData as v2APIKeyDataRouter,
} from './routes/v2';

import { healthCheck } from './routes/status';

import { getLogger } from './utils/logger';
import { RouteNotFoundError } from './utils/errors';
import { requestErrorHandler } from './middleware/requestErrorHandler';
Expand Down Expand Up @@ -101,6 +103,10 @@ app.use('/api/v2/secret', v2SecretRouter);
app.use('/api/v2/service-token', v2ServiceTokenDataRouter);
app.use('/api/v2/api-key-data', v2APIKeyDataRouter);


// Server status
app.use('/api', healthCheck)

//* Handle unrouted requests and respond with proper error message as well as status code
app.use((req, res, next) => {
if (res.headersSent) return next();
Expand Down
4 changes: 3 additions & 1 deletion backend/src/helpers/rateLimiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const apiLimiter = rateLimit({
max: 450,
standardHeaders: true,
legacyHeaders: false,
skip: (request) => request.path === '/healthcheck'
skip: (request) => {
return request.path === '/healthcheck' || request.path === '/api/status'
}
});

// 5 requests per hour
Expand Down
5 changes: 5 additions & 0 deletions backend/src/routes/status/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import healthCheck from './healthCheck';

export {
healthCheck
}
15 changes: 15 additions & 0 deletions backend/src/routes/status/status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import express, { Request, Response } from 'express';

const router = express.Router();

router.get(
'/status',
(req: Request, res: Response) => {
res.status(200).json({
date: new Date(),
message: 'Ok',
})
}
);

export default router

0 comments on commit cb60151

Please sign in to comment.