diff --git a/api/src/app.ts b/api/src/app.ts index 9b4a05f7d44..7f85f830d0c 100644 --- a/api/src/app.ts +++ b/api/src/app.ts @@ -21,6 +21,7 @@ import jwtAuthz from './plugins/fastify-jwt-authz'; import security from './plugins/security'; import sessionAuth from './plugins/session-auth'; import { settingRoutes } from './routes/settings'; +import { deprecatedEndpoints } from './routes/deprecated-endpoints'; import { auth0Routes, devLoginCallback } from './routes/auth'; import { testMiddleware } from './middleware'; import prismaPlugin from './db/prisma'; @@ -121,6 +122,7 @@ export const build = async ( void fastify.register(devLoginCallback, { prefix: '/auth' }); } void fastify.register(settingRoutes); + void fastify.register(deprecatedEndpoints); return fastify; }; diff --git a/api/src/routes/deprecated-endpoints.test.ts b/api/src/routes/deprecated-endpoints.test.ts new file mode 100644 index 00000000000..a62195cc386 --- /dev/null +++ b/api/src/routes/deprecated-endpoints.test.ts @@ -0,0 +1,33 @@ +import request from 'supertest'; + +import { build } from '../app'; +import { endpoints } from './deprecated-endpoints'; + +describe('Deprecated endpoints', () => { + let fastify: undefined | Awaited>; + + beforeAll(async () => { + fastify = await build(); + await fastify.ready(); + }, 20000); + + afterAll(async () => { + await fastify?.close(); + }); + + endpoints.forEach(([endpoint, method]) => { + test(`${method} ${endpoint} returns 410 status code with "info" message`, async () => { + const response = await request(fastify?.server)[ + method.toLowerCase() as 'get' | 'post' + ](endpoint); + + expect(response.status).toBe(410); + expect(response.body).toStrictEqual({ + message: { + type: 'info', + message: 'Please reload the app, this feature is no longer available.' + } + }); + }); + }); +}); diff --git a/api/src/routes/deprecated-endpoints.ts b/api/src/routes/deprecated-endpoints.ts new file mode 100644 index 00000000000..51d73270c37 --- /dev/null +++ b/api/src/routes/deprecated-endpoints.ts @@ -0,0 +1,49 @@ +import { + FastifyPluginCallbackTypebox, + Type +} from '@fastify/type-provider-typebox'; + +type Endpoints = [string, 'GET' | 'POST'][]; + +export const endpoints: Endpoints = [ + ['/refetch-user-completed-challenges', 'POST'], + ['/certificate/verify-can-claim-cert', 'GET'], + ['/api/github', 'GET'] +]; + +export const deprecatedEndpoints: FastifyPluginCallbackTypebox = ( + fastify, + _options, + done +) => { + endpoints.forEach(([endpoint, method]) => { + fastify.route({ + method, + url: endpoint, + schema: { + response: { + 410: Type.Object({ + message: Type.Object({ + type: Type.Literal('info'), + message: Type.Literal( + 'Please reload the app, this feature is no longer available.' + ) + }) + }) + } + }, + handler: async (_req, reply) => { + void reply.status(410); + return { + message: { + type: 'info', + message: + 'Please reload the app, this feature is no longer available.' + } + } as const; + } + }); + }); + + done(); +};