Skip to content

Commit

Permalink
Merge branch 'CodyTseng-feat-enhance-http-server-type' into 10.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Apr 5, 2023
2 parents 2eb932c + 702eebf commit 90a3416
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
5 changes: 3 additions & 2 deletions integration/hello-world/e2e/exceptions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { HttpServer, HttpStatus, INestApplication } from '@nestjs/common';
import { HttpStatus, INestApplication } from '@nestjs/common';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { RawServerDefault } from 'fastify';
import * as request from 'supertest';
import { ErrorsController } from '../src/errors/errors.controller';

describe('Error messages', () => {
let server: HttpServer;
let server: RawServerDefault;

describe('Express', () => {
let app: INestApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type HttpExceptionBodyMessage = string | string[];

export interface HttpExceptionBody {
message: HttpExceptionBodyMessage;
error?: string;
statusCode: number;
}
7 changes: 4 additions & 3 deletions packages/common/interfaces/nest-application.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { WebSocketAdapter } from './websockets/web-socket-adapter.interface';
*
* @publicApi
*/
export interface INestApplication extends INestApplicationContext {
export interface INestApplication<TServer = any>
extends INestApplicationContext {
/**
* A wrapper function around HTTP adapter method: `adapter.use()`.
* Example `app.use(cors())`
Expand Down Expand Up @@ -110,9 +111,9 @@ export interface INestApplication extends INestApplicationContext {
/**
* Returns the underlying native HTTP server.
*
* @returns {*}
* @returns {TServer}
*/
getHttpServer(): any;
getHttpServer(): TServer;

/**
* Returns the underlying HTTP adapter.
Expand Down
4 changes: 3 additions & 1 deletion packages/platform-express/adapters/express-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ type VersionedRoute = <
/**
* @publicApi
*/
export class ExpressAdapter extends AbstractHttpAdapter {
export class ExpressAdapter extends AbstractHttpAdapter<
http.Server | https.Server
> {
private readonly routerMethodFactory = new RouterMethodFactory();
private readonly logger = new Logger(ExpressAdapter.name);
private readonly openConnections = new Set<Duplex>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Server } from 'http';
import { INestApplication } from '@nestjs/common';
import type { Server as HttpServer } from 'http';
import type { Server as HttpsServer } from 'https';
import type { Server } from 'net';
import { NestExpressBodyParserOptions } from './nest-express-body-parser-options.interface';
import { ServeStaticOptions } from './serve-static-options.interface';
import { NestExpressBodyParserType } from './nest-express-body-parser.interface';
import { ServeStaticOptions } from './serve-static-options.interface';

/**
* Interface describing methods on NestExpressApplication.
Expand All @@ -11,7 +13,9 @@ import { NestExpressBodyParserType } from './nest-express-body-parser.interface'
*
* @publicApi
*/
export interface NestExpressApplication extends INestApplication {
export interface NestExpressApplication<
TServer extends HttpServer | HttpsServer = HttpServer,
> extends INestApplication<TServer> {
/**
* Starts the application.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
FastifyPluginOptions,
FastifyRegisterOptions,
RawServerBase,
RawServerDefault,
} from 'fastify';
import {
Chain as LightMyRequestChain,
Expand All @@ -19,7 +20,9 @@ import { NestFastifyBodyParserOptions } from './nest-fastify-body-parser-options
/**
* @publicApi
*/
export interface NestFastifyApplication extends INestApplication {
export interface NestFastifyApplication<
TServer extends RawServerBase = RawServerDefault,
> extends INestApplication<TServer> {
/**
* A wrapper function around native `fastify.register()` method.
* Example `app.register(require('@fastify/formbody'))
Expand Down

0 comments on commit 90a3416

Please sign in to comment.