Skip to content

Commit 10e0cb3

Browse files
authored
Merge pull request finos#1197 from andypols/add-proxy-healthcheck
chore: add /healthcheck endpoint to the proxy
2 parents 93a1aaf + dabbd44 commit 10e0cb3

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/proxy/routes/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,15 @@ const getRouter = async () => {
233233

234234
console.log('proxy keys registered: ', JSON.stringify(proxyKeys));
235235

236-
router.use('/', (req, res, next) => {
236+
router.use('/', ((req, res, next) => {
237+
if (req.path === '/healthcheck') {
238+
res.set('Cache-Control', 'no-cache, no-store, must-revalidate, proxy-revalidate');
239+
res.set('Pragma', 'no-cache');
240+
res.set('Expires', '0');
241+
res.set('Surrogate-Control', 'no-store');
242+
return res.status(200).send('OK');
243+
}
244+
237245
console.log(
238246
`processing request URL: '${req.url}' against registered proxy keys: ${JSON.stringify(proxyKeys)}`,
239247
);
@@ -247,7 +255,7 @@ const getRouter = async () => {
247255
// fallback
248256
console.log(`\tusing fallback`);
249257
return fallbackProxy(req, res, next);
250-
});
258+
}) as RequestHandler);
251259
return router;
252260
};
253261

test/testProxyRoute.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,31 @@ describe('proxy route helpers', () => {
200200
});
201201
});
202202

203+
describe('healthcheck route', () => {
204+
let app;
205+
206+
beforeEach(async () => {
207+
app = express();
208+
app.use('/', await getRouter());
209+
});
210+
211+
it('returns 200 OK with no-cache headers', async () => {
212+
const res = await chai.request(app).get('/healthcheck');
213+
214+
expect(res).to.have.status(200);
215+
expect(res.text).to.equal('OK');
216+
217+
// Basic header checks (values defined in route)
218+
expect(res).to.have.header(
219+
'cache-control',
220+
'no-cache, no-store, must-revalidate, proxy-revalidate',
221+
);
222+
expect(res).to.have.header('pragma', 'no-cache');
223+
expect(res).to.have.header('expires', '0');
224+
expect(res).to.have.header('surrogate-control', 'no-store');
225+
});
226+
});
227+
203228
describe('proxyFilter function', async () => {
204229
let proxyRoutes;
205230
let req;

0 commit comments

Comments
 (0)