|
1 | 1 | import {CustomParameterDecorator} from "./CustomParameterDecorator";
|
| 2 | +import {BaseDriver} from "./driver/BaseDriver"; |
2 | 3 | import {ExpressDriver} from "./driver/express/ExpressDriver";
|
3 | 4 | import {KoaDriver} from "./driver/koa/KoaDriver";
|
4 | 5 | import {MetadataArgsStorage} from "./metadata-builder/MetadataArgsStorage";
|
@@ -110,40 +111,46 @@ export function getMetadataArgsStorage(): MetadataArgsStorage {
|
110 | 111 | * Registers all loaded actions in your express application.
|
111 | 112 | */
|
112 | 113 | export function useExpressServer<T>(expressApp: T, options?: RoutingControllersOptions): T {
|
113 |
| - createExecutor(new ExpressDriver(expressApp), options || {}); |
114 |
| - return expressApp; |
| 114 | + const driver = new ExpressDriver(expressApp); |
| 115 | + return createServer(driver, options); |
115 | 116 | }
|
116 | 117 |
|
117 | 118 | /**
|
118 | 119 | * Registers all loaded actions in your express application.
|
119 | 120 | */
|
120 | 121 | export function createExpressServer(options?: RoutingControllersOptions): any {
|
121 | 122 | const driver = new ExpressDriver();
|
122 |
| - createExecutor(driver, options || {}); |
123 |
| - return driver.express; |
| 123 | + return createServer(driver, options); |
124 | 124 | }
|
125 | 125 |
|
126 | 126 | /**
|
127 | 127 | * Registers all loaded actions in your koa application.
|
128 | 128 | */
|
129 | 129 | export function useKoaServer<T>(koaApp: T, options?: RoutingControllersOptions): T {
|
130 |
| - createExecutor(new KoaDriver(koaApp), options || {}); |
131 |
| - return koaApp; |
| 130 | + const driver = new KoaDriver(koaApp); |
| 131 | + return createServer(driver, options); |
132 | 132 | }
|
133 | 133 |
|
134 | 134 | /**
|
135 | 135 | * Registers all loaded actions in your koa application.
|
136 | 136 | */
|
137 | 137 | export function createKoaServer(options?: RoutingControllersOptions): any {
|
138 | 138 | const driver = new KoaDriver();
|
139 |
| - createExecutor(driver, options || {}); |
140 |
| - 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; |
141 | 148 | }
|
142 | 149 |
|
143 | 150 | /**
|
144 | 151 | * Registers all loaded actions in your express application.
|
145 | 152 | */
|
146 |
| -export function createExecutor(driver: Driver, options: RoutingControllersOptions): void { |
| 153 | +export function createExecutor<T extends BaseDriver>(driver: T, options: RoutingControllersOptions = {}): void { |
147 | 154 |
|
148 | 155 | // import all controllers and middlewares and error handlers (new way)
|
149 | 156 | let controllerClasses: Function[];
|
|
0 commit comments