Add custom HTTP interceptor and spinner service for request handling; update CORS settings
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import { CustomHttpInterceptor } from './custom-http-interceptor';
|
||||
|
||||
describe('CustomHttpInterceptor', () => {
|
||||
it('should create an instance', () => {
|
||||
expect(new CustomHttpInterceptor()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse} from '@angular/common/http';
|
||||
import {Observable, tap} from 'rxjs';
|
||||
import {SpinnerService} from '../services/spinner.service';
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class CustomHttpInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(private spinnerService: SpinnerService) { }
|
||||
|
||||
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
|
||||
this.spinnerService.show();
|
||||
|
||||
return next.handle(req)
|
||||
.pipe(tap((event: HttpEvent<any>) => {
|
||||
if (event instanceof HttpResponse) {
|
||||
this.spinnerService.hide();
|
||||
}
|
||||
}, (error) => {
|
||||
this.spinnerService.hide();
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user