-
Notifications
You must be signed in to change notification settings - Fork 42
Description
This is an enhancement request.
Currently line 42 in your HttpInterceptor checks if the current request URL startsWith any URL in the exclude list. startsWith() only allows string matches. Can you update the check to accept regex as well? We have several server instances for our environment (Development, Test, Staging, Production) each with different hostnames. As the code is now, we must defined the URL of an excluded HTTP call for each instance in the exclude list.
@NgModule({
declarations: [AppComponent, HomeComponent],
imports: [
BrowserModule,
HttpClientModule,
NgxUiLoaderModule,
NgxUiLoaderHttpModule.forRoot({
showForeground: true,
exclude: [
'https://devServer/api/dontWatch',
'https://tstServer/api/dontWatch',
'https://stgServer/api/dontWatch',
'https://prdServer/api/dontWatch',
]
}),
],
bootstrap: [AppComponent]
})With the use of regex, we would be able to define it once using wildcards and regex special characters.
@NgModule({
declarations: [AppComponent, HomeComponent],
imports: [
BrowserModule,
HttpClientModule,
NgxUiLoaderModule,
NgxUiLoaderHttpModule.forRoot({
showForeground: true,
exclude: [
'/api/dontWatch$'
]
}),
],
bootstrap: [AppComponent]
})A mock-up of my proposal would be to replace
if (this.defaultConfig.exclude) {
// do not show the loader for api url in the `exclude` list
if (this.defaultConfig.exclude.findIndex(url => req.url.toLowerCase().startsWith(url)) !== -1) {
return next.handle(req);
}
}with
if (this.defaultConfig.exclude) {
// do not show the loader for api url in the `exclude` list
if (this.defaultConfig.exclude.findIndex(url => req.url.toLowerCase().matches(new RegExp(url.toLowerCase())) !== -1) {
return next.handle(req);
}
}The exclude list could then contain strings like api/dontWatch$, http://localhost/api/dontWatch, ^http://localhost/dontWatchAll.
I realize changing this may cause issues for users using the current implementation as there is an implicit ^ on all strings given. So an option could be to add an additional excludeRegex parameter to NgxUiLoaderHttpModule if you wanted to avoid that issue.