mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
add versioning support to the API
This commit is contained in:
16
src-ui/src/app/interceptors/api-version.interceptor.spec.ts
Normal file
16
src-ui/src/app/interceptors/api-version.interceptor.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ApiVersionInterceptor } from './api-version.interceptor';
|
||||
|
||||
describe('ApiVersionInterceptor', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({
|
||||
providers: [
|
||||
ApiVersionInterceptor
|
||||
]
|
||||
}));
|
||||
|
||||
it('should be created', () => {
|
||||
const interceptor: ApiVersionInterceptor = TestBed.inject(ApiVersionInterceptor);
|
||||
expect(interceptor).toBeTruthy();
|
||||
});
|
||||
});
|
25
src-ui/src/app/interceptors/api-version.interceptor.ts
Normal file
25
src-ui/src/app/interceptors/api-version.interceptor.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
HttpRequest,
|
||||
HttpHandler,
|
||||
HttpEvent,
|
||||
HttpInterceptor
|
||||
} from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
|
||||
@Injectable()
|
||||
export class ApiVersionInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor() {}
|
||||
|
||||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
request = request.clone({
|
||||
setHeaders: {
|
||||
'Accept': `application/json; version=${environment.apiVersion}`
|
||||
}
|
||||
})
|
||||
|
||||
return next.handle(request);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user