typescript-rest icon indicating copy to clipboard operation
typescript-rest copied to clipboard

loadControllers Not import sub directory

Open amwkr opened this issue 6 years ago • 1 comments

When using controller directory have subdicrectory.

directory example

src
├── controller
│   └── host
│       └── host-first-controller.ts
│       └── host-second-controller.ts
│   └── guest
│       └── guest-first-controller.ts
│       └── guest-second-controller.ts
│   └── main-controller.ts

I try include controller /**/*.ts but only load main-controller.ts

Server.loadControllers(this.app, 'controller/**/*.ts', __dirname);

Temporary use directly load directory.

Server.loadControllers(this.app, 'controller/*.ts', __dirname);
Server.loadControllers(this.app, 'controller/host/*.ts', __dirname);
Server.loadControllers(this.app, 'controller/guest/*.ts', __dirname);

please fix load subdirectory use /**/*.ts.

amwkr avatar Dec 03 '19 08:12 amwkr

Hi, I think that your code can not work once compiled, it will work in typescript (ie: if you run your code with ts-node), but not after compilation ... as the string controller/**/*.ts will not change, so, as after compilation phase, all your files are changed to javascript (with a js extension) so it will not match anything.

Try to do something like this :

Server.loadControllers(this.app, 'controller/**/*.js', __dirname);

Or

Server.loadControllers(this.app, 'controller/**/*Controller.*', __dirname);

Just do not reference .ts files ...

Regards ...

mimiz avatar Jul 28 '20 15:07 mimiz