Skip to content

Commit

Permalink
Add healtcheck middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Mar 6, 2023
1 parent 37269f2 commit 603e744
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ const applyConfig = (config) => {
middleware.all('**/_es/*', handler);
middleware.id = 'esProxyMiddleware';

const healthCheckMiddleware = require('./middleware/healthcheck').default;
middleware.all('**/_es_healthcheck/:id', healthCheckMiddleware);
middleware.id = 'esHealthcheck';

config.settings.expressMiddleware = [
...config.settings.expressMiddleware,
middleware,
Expand Down
16 changes: 16 additions & 0 deletions src/middleware/healthcheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { registry } from '@eeacms/search';

export default function healthcheck(req, res, next) {
const { id } = req.params;
const appConfig = registry.searchui[id];
if (appConfig.healthcheck) {
appConfig
.healthcheck(appConfig)
.then((body) => res.send(body))
.catch((body) => {
res.send({ error: body });
});
} else {
next();
}
}

0 comments on commit 603e744

Please sign in to comment.