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

feature() extract platforms (express/fastify/socket.io/ws) #1329

Merged
merged 5 commits into from Dec 29, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -23,8 +23,6 @@ export {
HttpServer,
INestApplication,
INestApplicationContext,
INestExpressApplication,
INestFastifyApplication,
INestMicroservice,
MiddlewareConsumer,
MiddlewareFunction,
@@ -1,4 +1,5 @@
import { RequestMethod } from '../../enums';
import { NestApplicationOptions } from './../../interfaces/nest-application-options.interface';

export type ErrorHandler<TRequest = any, TResponse = any> = (
error: any,
@@ -54,6 +55,8 @@ export interface HttpServer<TRequest = any, TResponse = any> {
getRequestMethod?(request: TRequest): string;
getRequestUrl?(request: TResponse): string;
getInstance(): any;
registerParserMiddleware(): any;
getHttpServer(): any;
initHttpServer(options: NestApplicationOptions): void;
close(): any;
}
@@ -23,8 +23,6 @@ export * from './modules/on-init.interface';
export * from './modules/provider.interface';
export * from './nest-application-context.interface';
export * from './nest-application.interface';
export * from './nest-express-application.interface';
export * from './nest-fastify-application.interface';
export * from './nest-microservice.interface';
export * from './on-application-bootstrap.interface';
export * from './request-mapping-metadata.interface';

This file was deleted.

This file was deleted.

@@ -0,0 +1,90 @@
import { HttpServer, RequestMethod } from '@nestjs/common';
import { RequestHandler } from '@nestjs/common/interfaces';
import { NestApplicationOptions } from '@nestjs/common/interfaces/nest-application-options.interface';

export abstract class AbstractHttpAdapter<T = any> implements HttpServer {
protected httpServer: T;

constructor(protected readonly instance: any) {}

public use(...args: any[]) {
return this.instance.use(...args);
}

public get(handler: RequestHandler);
public get(path: any, handler: RequestHandler);
public get(...args: any[]) {
return this.instance.get(...args);
}

public post(handler: RequestHandler);
public post(path: any, handler: RequestHandler);
public post(...args: any[]) {
return this.instance.post(...args);
}

public head(handler: RequestHandler);
public head(path: any, handler: RequestHandler);
public head(...args: any[]) {
return this.instance.head(...args);
}

public delete(handler: RequestHandler);
public delete(path: any, handler: RequestHandler);
public delete(...args: any[]) {
return this.instance.delete(...args);
}

public put(handler: RequestHandler);
public put(path: any, handler: RequestHandler);
public put(...args: any[]) {
return this.instance.put(...args);
}

public patch(handler: RequestHandler);
public patch(path: any, handler: RequestHandler);
public patch(...args: any[]) {
return this.instance.patch(...args);
}

public options(handler: RequestHandler);
public options(path: any, handler: RequestHandler);
public options(...args: any[]) {
return this.instance.options(...args);
}

public listen(port: string | number, callback?: () => void);
public listen(port: string | number, hostname: string, callback?: () => void);
public listen(port: any, hostname?: any, callback?: any) {
return this.instance.listen(port, hostname, callback);
}

public getHttpServer(): T {
return this.httpServer as T;
}

public setHttpServer(httpServer: T) {
this.httpServer = httpServer;
}

public getInstance(): any {
return this.instance;
}

abstract close();
abstract initHttpServer(options: NestApplicationOptions);
abstract useStaticAssets(path: string, options: any);
abstract setBaseViewsDir(path: string);
abstract setViewEngine(engine: string);
abstract getRequestMethod(request);
abstract getRequestUrl(request);
abstract reply(response, body: any, statusCode: number);
abstract render(response, view: string, options: any);
abstract setErrorHandler(handler: Function);
abstract setNotFoundHandler(handler: Function);
abstract setHeader(response, name: string, value: string);
abstract registerParserMiddleware();
abstract createMiddlewareFactory(
requestMethod: RequestMethod,
): (path: string, callback: Function) => any;
}
@@ -1 +1 @@
export * from './fastify-adapter';
export * from './http-adapter';
@@ -0,0 +1 @@
export * from './base-exception-filter';
@@ -0,0 +1 @@
export * from './application-ref-host';
@@ -8,11 +8,10 @@ import 'reflect-metadata';

export * from './adapters';
export { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_PIPE } from './constants';
export { BaseExceptionFilter } from './exceptions/base-exception-filter';
export { ApplicationReferenceHost } from './helpers/application-ref-host';
export { ModuleRef } from './injector/module-ref';
export { HTTP_SERVER_REF } from './injector/tokens';
export { MiddlewareBuilder } from './middleware/builder';
export * from './exceptions';
export * from './helpers';
export * from './injector';
export * from './middleware';
export * from './nest-application';
export * from './nest-application-context';
export { NestFactory } from './nest-factory';
@@ -1,2 +1,3 @@
export * from './module-ref';
export * from './modules-container';
export * from './tokens';
@@ -0,0 +1 @@
export * from './builder';
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.