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

feat(common)!: narrow getInstance return type for http adapters #10630

Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions packages/common/interfaces/http/http-server.interface.ts
Expand Up @@ -18,7 +18,11 @@ export type RequestHandler<TRequest = any, TResponse = any> = (
next?: Function,
) => any;

export interface HttpServer<TRequest = any, TResponse = any> {
export interface HttpServer<
TRequest = any,
TResponse = any,
ServerInstance = any,
> {
use(
handler:
| RequestHandler<TRequest, TResponse>
Expand Down Expand Up @@ -69,7 +73,7 @@ export interface HttpServer<TRequest = any, TResponse = any> {
getRequestHostname?(request: TRequest): string;
getRequestMethod?(request: TRequest): string;
getRequestUrl?(request: TRequest): string;
getInstance(): any;
getInstance(): ServerInstance;
registerParserMiddleware(...args: any[]): any;
enableCors(options: CorsOptions | CorsOptionsDelegate<TRequest>): any;
getHttpServer(): any;
Expand Down
@@ -1,7 +1,8 @@
import { INestApplication } from '@nestjs/common';
import type { Server as HttpServer } from 'http';
import type { Server as HttpsServer } from 'https';
import { INestApplication, HttpServer } from '@nestjs/common';
import type { Server as CoreHttpServer } from 'http';
import type { Server as CoreHttpsServer } from 'https';
import type { Server } from 'net';
import type { Express } from 'express';
import { NestExpressBodyParserOptions } from './nest-express-body-parser-options.interface';
import { NestExpressBodyParserType } from './nest-express-body-parser.interface';
import { ServeStaticOptions } from './serve-static-options.interface';
Expand All @@ -14,8 +15,15 @@ import { ServeStaticOptions } from './serve-static-options.interface';
* @publicApi
*/
export interface NestExpressApplication<
TServer extends HttpServer | HttpsServer = HttpServer,
TServer extends CoreHttpServer | CoreHttpsServer = CoreHttpServer,
> extends INestApplication<TServer> {
/**
* Returns the underlying HTTP adapter bounded to the Express.js app.
*
* @returns {HttpServer}
*/
getHttpAdapter(): HttpServer<Express.Request, Express.Response, Express>;

/**
* Starts the application.
*
Expand Down
@@ -1,11 +1,13 @@
import { INestApplication } from '@nestjs/common';
import { INestApplication, HttpServer } from '@nestjs/common';
import {
FastifyBodyParser,
FastifyInstance,
FastifyPluginAsync,
FastifyPluginCallback,
FastifyPluginOptions,
FastifyRegisterOptions,
FastifyRequest,
FastifyReply,
RawServerBase,
RawServerDefault,
} from 'fastify';
Expand All @@ -23,6 +25,13 @@ import { NestFastifyBodyParserOptions } from './nest-fastify-body-parser-options
export interface NestFastifyApplication<
TServer extends RawServerBase = RawServerDefault,
> extends INestApplication<TServer> {
/**
* Returns the underlying HTTP adapter bounded to a Fastify app.
*
* @returns {HttpServer}
*/
getHttpAdapter(): HttpServer<FastifyRequest, FastifyReply, FastifyInstance>;

/**
* A wrapper function around native `fastify.register()` method.
* Example `app.register(require('@fastify/formbody'))
Expand Down