Add custom HTTP interceptor and spinner service for request handling; update CORS settings
This commit is contained in:
+2
-2
@@ -22,6 +22,6 @@
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
|
||||
<button mat-raised-button (click)="zoomPlus()" >Generate</button>
|
||||
<button mat-raised-button (click)="zoomMinus()" >Generate</button>
|
||||
<!--<button mat-raised-button (click)="zoomPlus()" >Generate</button>
|
||||
<button mat-raised-button (click)="zoomMinus()" >Generate</button>-->
|
||||
<img src={{image.url}} />
|
||||
|
||||
@@ -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();
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { SpinnerService } from './spinner.service';
|
||||
|
||||
describe('SpinnerService', () => {
|
||||
let service: SpinnerService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(SpinnerService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {BehaviorSubject} from 'rxjs';
|
||||
|
||||
@Injectable({ providedIn: 'root'})
|
||||
export class SpinnerService {
|
||||
visibility: BehaviorSubject<boolean>;
|
||||
|
||||
constructor() {
|
||||
this.visibility = new BehaviorSubject(false);
|
||||
}
|
||||
|
||||
show() {
|
||||
this.visibility.next(true);
|
||||
}
|
||||
|
||||
hide() {
|
||||
this.visibility.next(false);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:4200", maxAge = 3600, allowCredentials="true")
|
||||
@CrossOrigin(origins = "http://localhost:4200, https://pony-sincere-chimp.ngrok-free.app/", maxAge = 3600, allowCredentials="true")
|
||||
@RestController
|
||||
@RequestMapping("/api/zhipuai")
|
||||
public class ImageController {
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
//@CrossOrigin(origins = "*", maxAge = 3600)
|
||||
@CrossOrigin(origins = "http://localhost:4200,https://a576-5-248-149-207.ngrok-free.app", maxAge = 3600, allowCredentials="true")
|
||||
@CrossOrigin(origins = "http://localhost:4200,https://a576-5-248-149-207.ngrok-free.app, https://pony-sincere-chimp.ngrok-free.app", maxAge = 3600, allowCredentials="true")
|
||||
@RestController
|
||||
@RequestMapping("/api/auth")
|
||||
public class AuthController {
|
||||
|
||||
Reference in New Issue
Block a user