Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sitecore-jss-proxy][templates/node-xmcloud-proxy] Health check endpoint and middleware #1928

Merged
merged 7 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Our versioning strategy is as follows:
- `scTextEmptyFieldEditingTemplate` for _scText_
* `[sitecore-jss-angular]` `[templates/angular-xmcloud]` Render clientScripts / clientData. The new `sc-editing-scripts` component is exposed from `sitecore-jss-angular` package and required to be rendered on the page to enable Metadata Edit mode. ([#1924](https://github.com/Sitecore/jss/pull/1924))
* `[sitecore-jss]` GenericFieldValue model is updated to accept Date type ([#1916](https://github.com/Sitecore/jss/pull/1916))
* `[template/node-xmcloud-proxy]` `[sitecore-jss-proxy]` Introduced /api/healthz endpoint ([#1928](https://github.com/Sitecore/jss/pull/1928))

### 🛠 Breaking Change

Expand Down
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 { healthCheck } 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.use(healthCheck());

/**
* Proxy editing requests through the editing router
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import express from 'express';
import request from 'supertest';
import { healthCheck } from './index';

describe('healthcheck router - /api/healthz', () => {
const app = express();

it('should handle request', async () => {
app.use(healthCheck());

request(app)
.get('/api/healthz')
.expect(200, 'Healthy');
});
});
15 changes: 15 additions & 0 deletions packages/sitecore-jss-proxy/src/middleware/healthcheck/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Router, Request, Response } from 'express';

/**
* Creates a router for health check requests.
* @returns {Router} Editing router
*/
export const healthCheck = (): Router => {
const router = Router();

router.get('/api/healthz', (_req: Request, res: Response) => {
res.status(200).send('Healthy');
});

return router;
};
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 { healthCheck } from './healthcheck';