mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat(api): add deployment version endpoint (#59841)
This commit is contained in:
committed by
GitHub
parent
aef4729ce3
commit
ae720e8282
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user