mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-11 07:00:41 -04:00
refactor(api): remove unused endpoints (#50252)
Also adds "dev" as an alias because I keep trying to use it.
This commit is contained in:
committed by
GitHub
parent
25f7697382
commit
7572f99f74
@@ -53,6 +53,7 @@
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.build.json",
|
||||
"clean": "rm -rf dist",
|
||||
"dev": "pnpm develop",
|
||||
"develop": "nodemon src/server.ts",
|
||||
"start": "FREECODECAMP_NODE_ENV=production node dist/server.js",
|
||||
"test": "jest --force-exit",
|
||||
|
||||
@@ -23,7 +23,6 @@ import sessionAuth from './plugins/session-auth';
|
||||
import { testRoutes } from './routes/test';
|
||||
import { settingRoutes } from './routes/settings';
|
||||
import { auth0Routes, devLoginCallback } from './routes/auth';
|
||||
import { testValidatedRoutes } from './routes/validation-test';
|
||||
import { testMiddleware } from './middleware';
|
||||
import prismaPlugin from './db/prisma';
|
||||
|
||||
@@ -124,7 +123,6 @@ export const build = async (
|
||||
void fastify.register(devLoginCallback, { prefix: '/auth' });
|
||||
}
|
||||
void fastify.register(settingRoutes);
|
||||
void fastify.register(testValidatedRoutes);
|
||||
|
||||
return fastify;
|
||||
};
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
import { Type } from '@fastify/type-provider-typebox';
|
||||
|
||||
import type { FastifyInstanceWithTypeProvider } from '../app';
|
||||
import { responseSchema, subSchema } from '../schemas/example';
|
||||
|
||||
export const testValidatedRoutes = (
|
||||
fastify: FastifyInstanceWithTypeProvider,
|
||||
_options: never,
|
||||
done: (err?: Error) => void
|
||||
): void => {
|
||||
fastify.get(
|
||||
'/route-with-validation',
|
||||
{
|
||||
schema: {
|
||||
querystring: Type.Object({
|
||||
foo: Type.Number(),
|
||||
bar: Type.String()
|
||||
})
|
||||
}
|
||||
},
|
||||
request => {
|
||||
const { foo, bar } = request.query;
|
||||
|
||||
// Eslint can use the types given by TypeBoxTypeProvider:
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
||||
const fooBar = foo + bar;
|
||||
return { foo, bar, fooBar };
|
||||
}
|
||||
);
|
||||
|
||||
fastify.post(
|
||||
'/route-with-validation-shared-schema',
|
||||
{
|
||||
schema: {
|
||||
body: Type.Object({
|
||||
foo: Type.Number(),
|
||||
bar: Type.String(),
|
||||
sub: subSchema
|
||||
}),
|
||||
response: {
|
||||
200: responseSchema
|
||||
}
|
||||
}
|
||||
},
|
||||
request => {
|
||||
const { foo, bar } = request.body;
|
||||
// The TypeProvider constrains this by requiring value: string and
|
||||
// otherValue: boolean. Anything else is a type error. 'ignored' is
|
||||
// neither type checked nor returned, so it's safe. 'optional' is
|
||||
// self-explanatory.
|
||||
return {
|
||||
value: bar,
|
||||
otherValue: !foo,
|
||||
ignored: 'not in reply',
|
||||
...(foo == 2 && { optional: 'optional' })
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
done();
|
||||
};
|
||||
Reference in New Issue
Block a user