Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(platform-fastify): use the route method to inject routes #13493

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 14 additions & 9 deletions packages/platform-fastify/adapters/fastify-adapter.ts
Expand Up @@ -32,11 +32,12 @@ import {
RawServerBase,
RawServerDefault,
RequestGenericInterface,
RouteOptions,
RouteShorthandOptions,
fastify,
} from 'fastify';
import * as Reply from 'fastify/lib/reply';
import { kRouteContext } from 'fastify/lib/symbols';
import { RouteShorthandMethod } from 'fastify/types/route';
import * as http2 from 'http2';
import * as https from 'https';
import {
Expand Down Expand Up @@ -683,6 +684,13 @@ export class FastifyAdapter<
const hasConfig = !isUndefined(routeConfig);
const hasConstraints = !isUndefined(routeConstraints);

const routeToInject: RouteOptions<TServer, TRawRequest, TRawResponse> &
RouteShorthandOptions = {
method: routerMethodKey,
url: args[0],
handler: handlerRef,
};

if (isVersioned || hasConstraints || hasConfig) {
const isPathAndRouteTuple = args.length === 2;
if (isPathAndRouteTuple) {
Expand All @@ -701,15 +709,12 @@ export class FastifyAdapter<
},
}),
};
const path = args[0];
return this.instance[routerMethodKey](path, options, handlerRef);

const routeToInjectWithOptions = { ...routeToInject, ...options };

return this.instance.route(routeToInjectWithOptions);
}
}

return this.instance[routerMethodKey](
...(args as Parameters<
RouteShorthandMethod<TServer, TRawRequest, TRawResponse>
>),
);
return this.instance.route(routeToInject);
}
}