@nestjs/platform-fastify 12.1.0 → 12.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -122,8 +122,8 @@ export declare class FastifyAdapter<TServer extends RawServerBase = RawServerDef
122
122
  inject(opts: InjectOptions | string): Promise<LightMyRequestResponse>;
123
123
  close(): Promise<void>;
124
124
  initHttpServer(options?: NestApplicationOptions): void;
125
- useStaticAssets(options: FastifyStaticOptions): Promise<any>;
126
- setViewEngine(options: FastifyViewOptions | string): Promise<any>;
125
+ useStaticAssets(options: FastifyStaticOptions): any;
126
+ setViewEngine(options: FastifyViewOptions | string): any;
127
127
  isHeadersSent(response: TReply): boolean;
128
128
  getHeader(response: any, name: string): any;
129
129
  setHeader(response: TReply, name: string, value: string): FastifyReply<RouteGenericInterface, TServer, TRawRequest, TRawResponse, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>;
@@ -280,8 +280,9 @@ export class FastifyAdapter extends AbstractHttpAdapter {
280
280
  }
281
281
  body = body.getStream();
282
282
  }
283
- if (fastifyReply.getHeader('Content-Type') !== undefined &&
284
- fastifyReply.getHeader('Content-Type') !== 'application/json' &&
283
+ const responseContentType = fastifyReply.getHeader('Content-Type');
284
+ if (typeof responseContentType === 'string' &&
285
+ !responseContentType.startsWith('application/json') &&
285
286
  body?.statusCode >= HttpStatus.BAD_REQUEST) {
286
287
  Logger.warn("Content-Type doesn't match Reply body, you might need a custom ExceptionFilter for non-JSON responses", FastifyAdapter.name);
287
288
  fastifyReply.header('Content-Type', 'application/json');
@@ -392,15 +393,20 @@ export class FastifyAdapter extends AbstractHttpAdapter {
392
393
  this.trackOpenConnections();
393
394
  }
394
395
  }
395
- async useStaticAssets(options) {
396
- return this.register(await loadPackage('@fastify/static', 'FastifyAdapter.useStaticAssets()', () => import('@fastify/static')), options);
396
+ // `register()` accepts a promise of a plugin, so the import is handed over
397
+ // unawaited on purpose. `NestApplication.useStaticAssets()` discards what
398
+ // this returns, so awaiting here would enqueue the plugin after the caller
399
+ // has already moved on to `listen()`.
400
+ useStaticAssets(options) {
401
+ return this.register(loadPackage('@fastify/static', 'FastifyAdapter.useStaticAssets()', () => import('@fastify/static')), options);
397
402
  }
398
- async setViewEngine(options) {
403
+ // Handed over unawaited for the same reason as `useStaticAssets()` above.
404
+ setViewEngine(options) {
399
405
  if (isString(options)) {
400
406
  new Logger('FastifyAdapter').error("setViewEngine() doesn't support a string argument.");
401
407
  process.exit(1);
402
408
  }
403
- return this.register(await loadPackage('@fastify/view', 'FastifyAdapter.setViewEngine()', () => import('@fastify/view')), options);
409
+ return this.register(loadPackage('@fastify/view', 'FastifyAdapter.setViewEngine()', () => import('@fastify/view')), options);
404
410
  }
405
411
  isHeadersSent(response) {
406
412
  return response.sent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/platform-fastify",
3
- "version": "12.1.0",
3
+ "version": "12.1.1",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@platform-fastify)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "license": "MIT",
@@ -54,5 +54,5 @@
54
54
  "optional": true
55
55
  }
56
56
  },
57
- "gitHead": "6739656fa3e8c98bd55883f0363a2254e6412232"
57
+ "gitHead": "9feedffde8ef8c86f0cd521153740575dc579d88"
58
58
  }