@@ -8,10 +8,13 @@ import { messages } from './constants';
88import { MicroservicesModule } from '@nestjs/microservices/microservices-module' ;
99import { Resolver } from './router/interfaces/resolver.interface' ;
1010import { INestApplication } from '@nestjs/common' ;
11+ import { ApplicationConfig } from './application-config' ;
12+ import { validatePath } from '@nestjs/common/utils/shared.utils' ;
1113
1214export class NestApplication implements INestApplication {
13- private readonly routesResolver : Resolver ;
15+ private readonly config = new ApplicationConfig ( ) ;
1416 private readonly logger = new Logger ( NestApplication . name ) ;
17+ private readonly routesResolver : Resolver ;
1518
1619 constructor (
1720 private readonly container : NestContainer ,
@@ -26,12 +29,27 @@ export class NestApplication implements INestApplication {
2629 MicroservicesModule . setupClients ( this . container ) ;
2730 }
2831
29- public listen ( port : number , callback ?: ( ) => void ) {
30- this . setupMiddlewares ( this . express ) ;
31- this . setupRoutes ( this . express ) ;
32+ public init ( ) {
33+ const router = ExpressAdapter . createRouter ( ) ;
34+ this . setupMiddlewares ( router ) ;
35+ this . setupRoutes ( router ) ;
36+
37+ this . express . use (
38+ validatePath ( this . config . getGlobalPrefix ( ) ) ,
39+ router ,
40+ ) ;
3241
3342 this . logger . log ( messages . APPLICATION_READY ) ;
34- return this . express . listen ( port , callback ) ;
43+ }
44+
45+ public listen ( port : number , callback ?: ( ) => void ) {
46+ const server = this . express . listen ( port , ( ) => {
47+ callback && callback . call ( callback , server ) ;
48+ } ) ;
49+ }
50+
51+ public setGlobalPrefix ( prefix : string ) {
52+ this . config . setGlobalPrefix ( prefix ) ;
3553 }
3654
3755 private setupMiddlewares ( instance ) {
0 commit comments