Skip to content

Commit 9f4bd4b

Browse files
authored
Merge pull request #3322 from SeedCompany/fastify/v5
2 parents f3b6057 + 54dc541 commit 9f4bd4b

File tree

3 files changed

+212
-196
lines changed

3 files changed

+212
-196
lines changed

package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
"@aws-sdk/client-s3": "^3.440.0",
3535
"@aws-sdk/s3-request-presigner": "^3.440.0",
3636
"@faker-js/faker": "^8.2.0",
37-
"@fastify/compress": "^7.0.3",
38-
"@fastify/cookie": "^9.4.0",
39-
"@fastify/cors": "^9.0.1",
37+
"@fastify/compress": "^8.0.1",
38+
"@fastify/cookie": "^11.0.1",
39+
"@fastify/cors": "^10.0.1",
4040
"@ffprobe-installer/ffprobe": "^2.1.2",
4141
"@golevelup/nestjs-discovery": "^4.0.0",
4242
"@graphql-hive/yoga": "^0.38.2",
@@ -71,8 +71,8 @@
7171
"extensionless": "^1.7.0",
7272
"fast-safe-stringify": "^2.1.1",
7373
"fastest-levenshtein": "^1.0.16",
74-
"fastify": "^4.28.1",
75-
"fastify-raw-body": "^4.3.0",
74+
"fastify": "^5.0.0",
75+
"fastify-raw-body": "^5.0.0",
7676
"file-type": "^18.6.0",
7777
"glob": "^10.3.10",
7878
"got": "^14.3.0",
@@ -159,6 +159,11 @@
159159
"@nestjs/cli/webpack": "npm:empty-npm-package@*",
160160
"@nestjs/cli/typescript": "^5.1.6",
161161
"@nestjs/graphql/graphql-ws": "^5",
162+
"@nestjs/platform-fastify/@fastify/cors": "^10",
163+
"@nestjs/platform-fastify/@fastify/formbody": "^8",
164+
"@nestjs/platform-fastify/@fastify/middie": "^9",
165+
"@nestjs/platform-fastify/fastify": "^5",
166+
"@nestjs/platform-fastify/light-my-request": "^6",
162167
"@whatwg-node/fetch": "patch:@whatwg-node/fetch@npm%3A0.9.22#~/.yarn/patches/@whatwg-node-fetch-npm-0.9.22-a60314fb39.patch",
163168
"subscriptions-transport-ws": "npm:empty-npm-package@*"
164169
},

src/core/http/http.adapter.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@ import {
1212
FastifyAdapter,
1313
NestFastifyApplication,
1414
} from '@nestjs/platform-fastify';
15-
import type { FastifyInstance, HTTPMethods, RouteOptions } from 'fastify';
15+
import type {
16+
FastifyInstance,
17+
FastifyReply,
18+
FastifyRequest,
19+
HTTPMethods,
20+
RawReplyDefaultExpression,
21+
RawRequestDefaultExpression,
22+
RawServerBase,
23+
RawServerDefault,
24+
RequestGenericInterface,
25+
RouteOptions,
26+
} from 'fastify';
1627
import rawBody from 'fastify-raw-body';
1728
import * as zlib from 'node:zlib';
1829
import { uniqueDiscoveredMethods } from '~/common/discovery-unique-methods';
@@ -34,8 +45,41 @@ export type NestHttpApplication = NestFastifyApplication & {
3445

3546
export class HttpAdapterHost extends HttpAdapterHostImpl<HttpAdapter> {}
3647

48+
type FastifyRawRequest<TServer extends RawServerBase> =
49+
RawRequestDefaultExpression<TServer> & {
50+
originalUrl?: string;
51+
};
52+
3753
// @ts-expect-error Convert private methods to protected
38-
class PatchedFastifyAdapter extends FastifyAdapter {
54+
class PatchedFastifyAdapter<
55+
TServer extends RawServerBase = RawServerDefault,
56+
TRawRequest extends FastifyRawRequest<TServer> = FastifyRawRequest<TServer>,
57+
TRawResponse extends RawReplyDefaultExpression<TServer> = RawReplyDefaultExpression<TServer>,
58+
TRequest extends FastifyRequest<
59+
RequestGenericInterface,
60+
TServer,
61+
TRawRequest
62+
> = FastifyRequest<RequestGenericInterface, TServer, TRawRequest>,
63+
TReply extends FastifyReply<
64+
RequestGenericInterface,
65+
TServer,
66+
TRawRequest,
67+
TRawResponse
68+
> = FastifyReply<RequestGenericInterface, TServer, TRawRequest, TRawResponse>,
69+
TInstance extends FastifyInstance<
70+
TServer,
71+
TRawRequest,
72+
TRawResponse
73+
> = FastifyInstance<TServer, TRawRequest, TRawResponse>,
74+
> extends FastifyAdapter<
75+
TServer,
76+
TRawRequest,
77+
TRawResponse,
78+
TRequest,
79+
// @ts-expect-error they haven't upgraded to v5 signature yet.
80+
TReply,
81+
TInstance
82+
> {
3983
protected injectRouteOptions(
4084
routerMethodKey: Uppercase<HTTPMethods>,
4185
...args: any[]

0 commit comments

Comments
 (0)