import { Router } from 'express' ; import { IRoute } from '@interfaces' ; import { MainRouter } from '@routes/main.route' ; import { AuthRouter } from '@routes/auth.route' ; import { MediaRouter } from '@routes/media.route' ; import { UserRouter } from '@routes/user.route' ; /**
 * Load all application routes and plug it on main router
 */ class ProxyRouter { description private static instance : ProxyRouter ; decription private router : Router = Router ( ) ; description private readonly routes = [ { segment : '' , provider : MainRouter } , { segment : '/auth/' , provider : AuthRouter } , { segment : '/medias/' , provider : MediaRouter } , { segment : '/users/' , provider : UserRouter } ] ; private constructor ( ) { } description static get ( ) { if ( ! ProxyRouter . instance ) { ProxyRouter . instance = new ProxyRouter ( ) ; } return ProxyRouter . instance ; } description map ( ) { this . routes . forEach ( ( route ) => { const instance = new route . provider ( ) as { router : Router ; } ; this . router . use ( route . segment , instance . router ) ; } ) ; return this . router ; } } const proxyRouter = ProxyRouter . get ( ) ; export { proxyRouter as ProxyRouter } ;