Set prefix in all controllers
ivanguimam opened this issue · 4 comments
I have the same problem this issue #48.
Only I'm using inversify to inject the services into my controllers, so I can't use a parent controller.
ControllerExample.ts
import { Controller, Get, Middleware } from '@overnightjs/core'
import { injectable, inject } from 'inversify'
import TYPES from '@src/ioc/types'
import BannerService from './BannerService'
@injectable()
@Controller('banner')
class BannerController {
private bannerService: BannerService
constructor(@inject(TYPES.BannerService) bannerService: BannerService) {
this.bannerService = bannerService
}
}
export BannerController
Server.ts
import DIContainer from './ioc'
import TYPES from './ioc/types'
import BannerController from './modules/banner/BannerController'
...
const bannerController = DIContainer.get<BannerController>(TYPES.BannerController)
super.addControllers([bannerController])
I managed to solve part of my problem with this snippet of code:
const bannerController = DIContainer.get<BannerController>(TYPES.BannerController)
const termsController = DIContainer.get<TermsController>(TYPES.TermsController)
super.addControllers([bannerController, termsController])
this.app.use('/app', this.app._router)
But before I had a route /banner
, now I have two routes, one /banner
and another /app/banner
Just my two cents: @seanpmaxwell told me that his goal with OvernightJS is to add first-class TypeScript support to Express, not add additional features like prefixes.
In my project staart/api (Express/TypeScript starter for SaaS), I built on top of OvernightJS and added more opinionated features like prefix injection, async return support, etc. I think that's the best way for you too. 😉
Can I close this issue in that case
Closing issue