-
Notifications
You must be signed in to change notification settings - Fork 393
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
Nesting controllers #322
Comments
You cannot do it the way you describe it, and you should not do it. however, you can do it. routing-controllers expects all of its routes to be preloaded at startup time like: import 'reflect-metadata';
import { useExpressServer } from 'routing-controllers';
// other imports
import './routes';
class App {
public express: express.Application = express();
constructor() {
useExpressServer(this.express, {
// your config
});
}
}
export default new App().express; And you can prefix your routes via: @JsonController('/v1/categories')
export class CategoriesRoute {
// your route handlers here
} So if you structure your routes into the // in routes/index.ts
export * from './v1';
export * from './v2'; However, I strongly advise you to not do this. Until you don't make a breaking change you don't have to update the version number and as soon as you need to you should copy-paste your current app, and create a separate app from it for v2. If you don't do it sooner or later your app will become a mess as you need to keep all the old logic and a) monkey patch the new logic into it (I mean in services), b) start copying only services both way your codebase will start to be filled with hacks and duplicated code which will make maintenance superhard. In the future, we may have some support for versioning though, a decorator like |
Stale issue message |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm wondering because i don't see it in the documentation in the README, does the controller system all for nesting controllers. Express router supports this, just trying to find out if controllers do in routing-controllers.
Use case:
/api
/api/v1
/api/v1/user
i'd like to setup a controller for api that would point at a folder for its controllers. In that folder, i could setup multiple folders for v1, v2, etc. In those folders would be the controllers for the respective versions.
The text was updated successfully, but these errors were encountered: