diff --git a/CHANGELOG.md b/CHANGELOG.md index ec06f0b97f..96cf53a426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/create-sitecore-jss/src/templates/node-xmcloud-proxy/src/index.ts b/packages/create-sitecore-jss/src/templates/node-xmcloud-proxy/src/index.ts index 6431f400f8..65d1f3f8cf 100644 --- a/packages/create-sitecore-jss/src/templates/node-xmcloud-proxy/src/index.ts +++ b/packages/create-sitecore-jss/src/templates/node-xmcloud-proxy/src/index.ts @@ -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(); @@ -127,6 +128,11 @@ server.use( }) ); +/** + * The health check endpoint + */ +server.use(healthCheck()); + /** * Proxy editing requests through the editing router */ diff --git a/packages/sitecore-jss-proxy/src/middleware/healthcheck/index.test.ts b/packages/sitecore-jss-proxy/src/middleware/healthcheck/index.test.ts new file mode 100644 index 0000000000..252b4928d1 --- /dev/null +++ b/packages/sitecore-jss-proxy/src/middleware/healthcheck/index.test.ts @@ -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'); + }); +}); diff --git a/packages/sitecore-jss-proxy/src/middleware/healthcheck/index.ts b/packages/sitecore-jss-proxy/src/middleware/healthcheck/index.ts new file mode 100644 index 0000000000..2ebbc0e04f --- /dev/null +++ b/packages/sitecore-jss-proxy/src/middleware/healthcheck/index.ts @@ -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; +}; diff --git a/packages/sitecore-jss-proxy/src/middleware/index.ts b/packages/sitecore-jss-proxy/src/middleware/index.ts index a517e03e02..4b614bde3c 100644 --- a/packages/sitecore-jss-proxy/src/middleware/index.ts +++ b/packages/sitecore-jss-proxy/src/middleware/index.ts @@ -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';