@@ -54,7 +54,7 @@ export class RouterExplorer {
5454 private readonly injector ?: Injector ,
5555 private readonly routerProxy ?: RouterProxy ,
5656 private readonly exceptionsFilter ?: ExceptionsFilter ,
57- config ?: ApplicationConfig ,
57+ private readonly config ?: ApplicationConfig ,
5858 ) {
5959 this . executionContextCreator = new RouterExecutionContext (
6060 new RouteParamsFactory ( ) ,
@@ -162,10 +162,6 @@ export class RouterExplorer {
162162 basePath ,
163163 host ,
164164 ) ;
165- path . forEach ( item => {
166- const pathStr = this . stripEndSlash ( basePath ) + this . stripEndSlash ( item ) ;
167- this . logger . log ( ROUTE_MAPPED_MESSAGE ( pathStr , requestMethod ) ) ;
168- } ) ;
169165 } ) ;
170166 }
171167
@@ -211,8 +207,58 @@ export class RouterExplorer {
211207
212208 const hostHandler = this . applyHostFilter ( host , proxy ) ;
213209 paths . forEach ( path => {
214- const fullPath = this . stripEndSlash ( basePath ) + path ;
215- routerMethod ( this . stripEndSlash ( fullPath ) || '/' , hostHandler ) ;
210+ const fullPath = this . stripEndSlash ( basePath ) + this . stripEndSlash ( path ) ;
211+ const unprefixedFullPath = this . removeGlobalPrefixFromPath ( fullPath ) ;
212+
213+ const isExcludedOfGlobalPrefix = this . isExcludedOfGlobalPrefix (
214+ unprefixedFullPath ,
215+ requestMethod ,
216+ ) ;
217+ const finalPath = isExcludedOfGlobalPrefix
218+ ? unprefixedFullPath
219+ : fullPath ;
220+
221+
8026
this . logger . log ( ROUTE_MAPPED_MESSAGE ( finalPath , requestMethod ) ) ;
222+ routerMethod ( finalPath || '/' , hostHandler ) ;
223+ } ) ;
224+ }
225+
226+ public removeGlobalPrefixFromPath ( path : string ) {
227+ const globalPrefix = validatePath ( this . config . getGlobalPrefix ( ) ) ;
228+ return path . replace ( globalPrefix , '' ) ;
229+ }
230+
231+ private isExcludedOfGlobalPrefix ( path : string , requestMethod : RequestMethod ) {
232+ const options = this . config . getGlobalPrefixOptions ( ) ;
233+ if ( ! options . exclude ) {
234+ return false ;
235+ }
236+
237+ const excludedRouteInfos = options . exclude . map ( route => {
238+ if ( isString ( route ) ) {
239+ return {
240+ path : this . validateRoutePath ( route ) ,
241+ method : RequestMethod . ALL ,
242+ } ;
243+ }
244+ return {
245+ path : this . validateRoutePath ( route . path ) ,
246+ method : route . method ,
247+ } ;
248+ } ) ;
249+
250+ return excludedRouteInfos . some ( route => {
251+ if ( route . path !== path ) {
252+ return false ;
253+ }
254+ if (
255+ route . method &&
256+ route . method !== RequestMethod . ALL &&
257+ route . method !== requestMethod
258+ ) {
259+ return false ;
260+ }
261+ return true ;
216262 } ) ;
217263 }
218264
0 commit comments