feat(api): add deployment version endpoint (#59841)

This commit is contained in:
Mrugesh Mohapatra
2025-04-22 01:00:20 +05:30
committed by GitHub
parent aef4729ce3
commit ae720e8282
3 changed files with 19 additions and 0 deletions
+10
View File
@@ -1,4 +1,5 @@
import { setupServer, superRequest } from '../../../jest.utils';
import { DEPLOYMENT_VERSION } from '../../utils/env';
describe('/status', () => {
setupServer();
@@ -11,4 +12,13 @@ describe('/status', () => {
expect(response.body).toStrictEqual({ msg: 'pong' });
expect(response.status).toBe(200);
});
test('GET returns 200 status code with version', async () => {
const response = await superRequest('/status/version', {
method: 'GET'
});
expect(response.body).toStrictEqual({ version: DEPLOYMENT_VERSION });
expect(response.status).toBe(200);
});
});
+7
View File
@@ -1,5 +1,7 @@
import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox';
import { DEPLOYMENT_VERSION } from '../../utils/env';
/**
* Plugin for the health check endpoint.
*
@@ -18,5 +20,10 @@ export const statusRoute: FastifyPluginCallbackTypebox = (
return { msg: 'pong' };
});
fastify.get('/status/version', async (req, _reply) => {
fastify.log.child({ req }).debug('version');
return { version: DEPLOYMENT_VERSION };
});
done();
};
+2
View File
@@ -90,6 +90,7 @@ if (process.env.FREECODECAMP_NODE_ENV !== 'development') {
assert.notEqual(process.env.COOKIE_SECRET, 'a_cookie_secret');
assert.ok(process.env.SENTRY_DSN);
assert.ok(process.env.SENTRY_ENVIRONMENT);
assert.ok(process.env.DEPLOYMENT_VERSION);
// The following values can exist in development, but production-like
// environments need to override the defaults.
assert.notEqual(
@@ -210,3 +211,4 @@ function undefinedOrBool(val: string | undefined): undefined | boolean {
}
export const SCREENSHOT_SERVICE_LOCATION =
process.env.SCREENSHOT_SERVICE_LOCATION;
export const DEPLOYMENT_VERSION = process.env.DEPLOYMENT_VERSION || 'unknown';