Skip to content

Commit

Permalink
feat(common): narrow getInstance return type for http platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Dec 4, 2022
1 parent ff15bd9 commit a04a9ce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
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 @@ -68,7 +72,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,5 +1,6 @@
import { Server } from 'net';
import { INestApplication } from '@nestjs/common';
import { Express } from 'express';
import { INestApplication, HttpServer } from '@nestjs/common';
import { ServeStaticOptions } from './serve-static-options.interface';

/**
Expand All @@ -10,6 +11,13 @@ import { ServeStaticOptions } from './serve-static-options.interface';
* @publicApi
*/
export interface NestExpressApplication extends INestApplication {
/**
* Returns the underlying HTTP adapter bounded to an Express.js app.
*
* @returns {HttpServer}
*/
getHttpAdapter(): HttpServer<Express.Request, Express.Response, Express>;

/**
* Starts the application.
*
Expand Down
@@ -1,10 +1,12 @@
import { INestApplication } from '@nestjs/common';
import { INestApplication, HttpServer } from '@nestjs/common';
import {
FastifyInstance,
FastifyPluginAsync,
FastifyPluginCallback,
FastifyPluginOptions,
FastifyRegisterOptions,
FastifyRequest,
FastifyReply,
} from 'fastify';
import {
Chain as LightMyRequestChain,
Expand All @@ -14,6 +16,13 @@ import {
import { FastifyStaticOptions, PointOfViewOptions } from './external';

export interface NestFastifyApplication extends INestApplication {
/**
* Returns the underlying HTTP adapter bounded to an Express.js app.
*
* @returns {HttpServer}
*/
getHttpAdapter(): HttpServer<FastifyRequest, FastifyReply, FastifyInstance>;

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

0 comments on commit a04a9ce

Please sign in to comment.