Skip to content

Commit

Permalink
the health check endpoint and middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
yavorsk committed Sep 12, 2024
1 parent 103e009 commit f5ecba5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import compression from 'compression';
import { createProxyMiddleware } from 'http-proxy-middleware';
import { debug } from '@sitecore-jss/sitecore-jss';
import { editingRouter } from '@sitecore-jss/sitecore-jss-proxy';
import { healthCheckMiddleware } from '@sitecore-jss/sitecore-jss-proxy';
import { config } from './config';

const server = express();
Expand Down Expand Up @@ -127,6 +128,11 @@ server.use(
})
);

/**
* The health check endpoint
*/
server.get('/api/healthz', healthCheckMiddleware());

/**
* Proxy editing requests through the editing router
*/
Expand Down
1 change: 1 addition & 0 deletions packages/sitecore-jss-proxy/src/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// eslint-disable-next-line prettier/prettier
export * as headlessProxy from './headless-ssr-proxy';
export { editingRouter } from './editing';
export { healthCheckMiddleware } from './monitoring';
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import express from 'express';
import request from 'supertest';
import { healthCheckMiddleware } from './index';

describe('editingRouter - /editing/render', () => {
const app = express();

it('should handle request', async () => {
app.get('/api/halthz', healthCheckMiddleware());

request(app)
.get('/api/halthz')
.expect(200, 'Healthy');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Request, Response } from 'express';

/**
* Middleware to handle health check requests
*/
export const healthCheckMiddleware = () => (_req: Request, res: Response): void => {
res.status(200).send('Healthy');
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { healthCheckMiddleware } from './healthcheck-middleware';

0 comments on commit f5ecba5

Please sign in to comment.