11import { CustomParameterDecorator } from "./CustomParameterDecorator" ;
2- import { Driver } from "./driver/Driver " ;
2+ import { BaseDriver } from "./driver/BaseDriver " ;
33import { ExpressDriver } from "./driver/express/ExpressDriver" ;
44import { KoaDriver } from "./driver/koa/KoaDriver" ;
55import { MetadataArgsStorage } from "./metadata-builder/MetadataArgsStorage" ;
@@ -88,7 +88,6 @@ export * from "./RoleChecker";
8888export * from "./Action" ;
8989export * from "./InterceptorInterface" ;
9090
91- export * from "./driver/Driver" ;
9291export * from "./driver/BaseDriver" ;
9392export * from "./driver/express/ExpressDriver" ;
9493export * from "./driver/koa/KoaDriver" ;
@@ -112,40 +111,46 @@ export function getMetadataArgsStorage(): MetadataArgsStorage {
112111 * Registers all loaded actions in your express application.
113112 */
114113export function useExpressServer < T > ( expressApp : T , options ?: RoutingControllersOptions ) : T {
115- createExecutor ( new ExpressDriver ( expressApp ) , options || { } ) ;
116- return expressApp ;
114+ const driver = new ExpressDriver ( expressApp ) ;
115+ return createServer ( driver , options ) ;
117116}
118117
119118/**
120119 * Registers all loaded actions in your express application.
121120 */
122121export function createExpressServer ( options ?: RoutingControllersOptions ) : any {
123122 const driver = new ExpressDriver ( ) ;
124- createExecutor ( driver , options || { } ) ;
125- return driver . express ;
123+ return createServer ( driver , options ) ;
126124}
127125
128126/**
129127 * Registers all loaded actions in your koa application.
130128 */
131129export function useKoaServer < T > ( koaApp : T , options ?: RoutingControllersOptions ) : T {
132- createExecutor ( new KoaDriver ( koaApp ) , options || { } ) ;
133- return koaApp ;
130+ const driver = new KoaDriver ( koaApp ) ;
131+ return createServer ( driver , options ) ;
134132}
135133
136134/**
137135 * Registers all loaded actions in your koa application.
138136 */
139137export function createKoaServer ( options ?: RoutingControllersOptions ) : any {
140138 const driver = new KoaDriver ( ) ;
141- createExecutor ( driver , options || { } ) ;
142- return driver . koa ;
139+ return createServer ( driver , options ) ;
140+ }
141+
142+ /**
143+ * Registers all loaded actions in your application using selected driver.
144+ */
145+ export function createServer < T extends BaseDriver > ( driver : T , options ?: RoutingControllersOptions ) : any {
146+ createExecutor ( driver , options ) ;
147+ return driver . app ;
143148}
144149
145150/**
146151 * Registers all loaded actions in your express application.
147152 */
148- export function createExecutor ( driver : Driver , options : RoutingControllersOptions ) : void {
153+ export function createExecutor < T extends BaseDriver > ( driver : T , options : RoutingControllersOptions = { } ) : void {
149154
150155 // import all controllers and middlewares and error handlers (new way)
151156 let controllerClasses : Function [ ] ;
0 commit comments