diff --git a/packages/common/interfaces/http/http-server.interface.ts b/packages/common/interfaces/http/http-server.interface.ts index 0fc061455cb..8bf7e49a965 100644 --- a/packages/common/interfaces/http/http-server.interface.ts +++ b/packages/common/interfaces/http/http-server.interface.ts @@ -18,7 +18,11 @@ export type RequestHandler = ( next?: Function, ) => any; -export interface HttpServer { +export interface HttpServer< + TRequest = any, + TResponse = any, + ServerInstance = any, +> { use( handler: | RequestHandler @@ -69,7 +73,7 @@ export interface HttpServer { getRequestHostname?(request: TRequest): string; getRequestMethod?(request: TRequest): string; getRequestUrl?(request: TRequest): string; - getInstance(): any; + getInstance(): ServerInstance; registerParserMiddleware(...args: any[]): any; enableCors(options: CorsOptions | CorsOptionsDelegate): any; getHttpServer(): any; diff --git a/packages/platform-express/interfaces/nest-express-application.interface.ts b/packages/platform-express/interfaces/nest-express-application.interface.ts index d096c7b166b..cfabd63d9e3 100644 --- a/packages/platform-express/interfaces/nest-express-application.interface.ts +++ b/packages/platform-express/interfaces/nest-express-application.interface.ts @@ -1,7 +1,8 @@ import { Server } from 'http'; -import { INestApplication } from '@nestjs/common'; +import { INestApplication, HttpServer } from '@nestjs/common'; import * as bodyparser from 'body-parser'; import { NestExpressBodyParserOptions } from './nest-express-body-parser-options.interface'; +import { Express } from 'express'; import { ServeStaticOptions } from './serve-static-options.interface'; /** @@ -12,6 +13,13 @@ import { ServeStaticOptions } from './serve-static-options.interface'; * @publicApi */ export interface NestExpressApplication extends INestApplication { + /** + * Returns the underlying HTTP adapter bounded to the Express.js app. + * + * @returns {HttpServer} + */ + getHttpAdapter(): HttpServer; + /** * Starts the application. * diff --git a/packages/platform-fastify/interfaces/nest-fastify-application.interface.ts b/packages/platform-fastify/interfaces/nest-fastify-application.interface.ts index 26b106516dd..16569631eaa 100644 --- a/packages/platform-fastify/interfaces/nest-fastify-application.interface.ts +++ b/packages/platform-fastify/interfaces/nest-fastify-application.interface.ts @@ -1,4 +1,4 @@ -import { INestApplication } from '@nestjs/common'; +import { INestApplication, HttpServer } from '@nestjs/common'; import { FastifyBodyParser, FastifyInstance, @@ -6,6 +6,8 @@ import { FastifyPluginCallback, FastifyPluginOptions, FastifyRegisterOptions, + FastifyRequest, + FastifyReply, RawServerBase, } from 'fastify'; import { @@ -20,6 +22,13 @@ import { NestFastifyBodyParserOptions } from './nest-fastify-body-parser-options * @publicApi */ export interface NestFastifyApplication extends INestApplication { + /** + * Returns the underlying HTTP adapter bounded to a Fastify app. + * + * @returns {HttpServer} + */ + getHttpAdapter(): HttpServer; + /** * A wrapper function around native `fastify.register()` method. * Example `app.register(require('@fastify/formbody'))