mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-02 07:01:28 -04:00
feat(api): gate classroom endpoints behind flag
This commit is contained in:
@@ -41,6 +41,7 @@ import {
|
||||
FCC_ENABLE_SWAGGER_UI,
|
||||
FCC_ENABLE_SHADOW_CAPTURE,
|
||||
FCC_ENABLE_SENTRY_ROUTES,
|
||||
FCC_ENABLE_CLASSROOM,
|
||||
FREECODECAMP_NODE_ENV,
|
||||
GROWTHBOOK_FASTIFY_API_HOST,
|
||||
GROWTHBOOK_FASTIFY_CLIENT_KEY
|
||||
@@ -237,11 +238,13 @@ export const build = async (
|
||||
});
|
||||
void fastify.register(examEnvironmentOpenRoutes);
|
||||
|
||||
// Service-to-service app routes (API key auth):
|
||||
void fastify.register(async function (fastify) {
|
||||
fastify.addHook('onRequest', fastify.validateBearerToken);
|
||||
await fastify.register(classroomRoutes, { prefix: '/apps/classroom' });
|
||||
});
|
||||
// Service-to-service app routes (API key auth), gated by the classroom flag:
|
||||
if (FCC_ENABLE_CLASSROOM ?? fastify.gb.isOn('classroom-mode')) {
|
||||
void fastify.register(async function (fastify) {
|
||||
fastify.addHook('onRequest', fastify.validateBearerToken);
|
||||
await fastify.register(classroomRoutes, { prefix: '/apps/classroom' });
|
||||
});
|
||||
}
|
||||
|
||||
if (FCC_ENABLE_SENTRY_ROUTES ?? fastify.gb.isOn('sentry-routes')) {
|
||||
void fastify.register(publicRoutes.sentryRoutes);
|
||||
|
||||
@@ -4,7 +4,8 @@ vi.mock('../../utils/env', async importOriginal => {
|
||||
const actual = await importOriginal<typeof import('../../utils/env.js')>();
|
||||
return {
|
||||
...actual,
|
||||
TPA_API_BEARER_TOKEN: 'test-classroom-api-secret'
|
||||
TPA_API_BEARER_TOKEN: 'test-classroom-api-secret',
|
||||
FCC_ENABLE_CLASSROOM: true
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -166,15 +166,17 @@ if (process.env.FREECODECAMP_NODE_ENV !== 'development') {
|
||||
'fastify_api_sdk_client_key_from_growthbook_dashboard',
|
||||
'The GROWTHBOOK_FASTIFY_CLIENT_KEY env should be changed from the default value.'
|
||||
);
|
||||
assert.ok(
|
||||
process.env.TPA_API_BEARER_TOKEN,
|
||||
'TPA_API_BEARER_TOKEN should be set.'
|
||||
);
|
||||
assert.notEqual(
|
||||
process.env.TPA_API_BEARER_TOKEN,
|
||||
'tpa_api_bearer_token_from_dashboard',
|
||||
'The TPA_API_BEARER_TOKEN env should be changed from the default value.'
|
||||
);
|
||||
if (process.env.FCC_ENABLE_CLASSROOM === 'true') {
|
||||
assert.ok(
|
||||
process.env.TPA_API_BEARER_TOKEN,
|
||||
'TPA_API_BEARER_TOKEN should be set.'
|
||||
);
|
||||
assert.notEqual(
|
||||
process.env.TPA_API_BEARER_TOKEN,
|
||||
'tpa_api_bearer_token_from_dashboard',
|
||||
'The TPA_API_BEARER_TOKEN env should be changed from the default value.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const HOME_LOCATION = process.env.HOME_LOCATION;
|
||||
@@ -211,6 +213,9 @@ export const FCC_ENABLE_SHADOW_CAPTURE = undefinedOrBool(
|
||||
export const FCC_ENABLE_SENTRY_ROUTES = undefinedOrBool(
|
||||
process.env.FCC_ENABLE_SENTRY_ROUTES
|
||||
);
|
||||
export const FCC_ENABLE_CLASSROOM = undefinedOrBool(
|
||||
process.env.FCC_ENABLE_CLASSROOM
|
||||
);
|
||||
export const FREECODECAMP_NODE_ENV = _FREECODECAMP_NODE_ENV;
|
||||
export const DEPLOYMENT_ENV = process.env.DEPLOYMENT_ENV;
|
||||
export const SENTRY_DSN =
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"EMAIL_PROVIDER",
|
||||
"FCC_API_LOG_LEVEL",
|
||||
"FCC_API_LOG_TRANSPORT",
|
||||
"FCC_ENABLE_CLASSROOM",
|
||||
"FCC_ENABLE_DEV_LOGIN_MODE",
|
||||
"FCC_ENABLE_SENTRY_ROUTES",
|
||||
"FCC_ENABLE_SHADOW_CAPTURE",
|
||||
@@ -58,6 +59,7 @@
|
||||
"EMAIL_PROVIDER",
|
||||
"FCC_API_LOG_LEVEL",
|
||||
"FCC_API_LOG_TRANSPORT",
|
||||
"FCC_ENABLE_CLASSROOM",
|
||||
"FCC_ENABLE_DEV_LOGIN_MODE",
|
||||
"FCC_ENABLE_SENTRY_ROUTES",
|
||||
"FCC_ENABLE_SHADOW_CAPTURE",
|
||||
|
||||
@@ -69,6 +69,7 @@ FCC_ENABLE_SWAGGER_UI=true
|
||||
FCC_ENABLE_DEV_LOGIN_MODE=true
|
||||
FCC_ENABLE_SHADOW_CAPTURE=false
|
||||
FCC_ENABLE_SENTRY_ROUTES=false
|
||||
FCC_ENABLE_CLASSROOM=false
|
||||
FCC_API_LOG_LEVEL=info
|
||||
FCC_API_LOG_TRANSPORT=pretty
|
||||
|
||||
|
||||
Reference in New Issue
Block a user