Sprint 9: add tenant-driven API resolution layer
This commit is contained in:
18
src/app/interceptors/api-base-url.interceptor.ts
Normal file
18
src/app/interceptors/api-base-url.interceptor.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { HttpInterceptorFn } from '@angular/common/http';
|
||||
import { inject } from '@angular/core';
|
||||
import { ApiConfigService } from '../core/config/api-config.service';
|
||||
|
||||
export const apiBaseUrlInterceptor: HttpInterceptorFn = (req, next) => {
|
||||
const apiConfig = inject(ApiConfigService);
|
||||
|
||||
if (!req.url.startsWith('/api')) {
|
||||
return next(req);
|
||||
}
|
||||
|
||||
const resolvedUrl = apiConfig.toApiUrl(req.url);
|
||||
if (resolvedUrl === req.url) {
|
||||
return next(req);
|
||||
}
|
||||
|
||||
return next(req.clone({ url: resolvedUrl }));
|
||||
};
|
||||
@@ -1,9 +1,9 @@
|
||||
import { HttpInterceptorFn } from '@angular/common/http';
|
||||
import { inject } from '@angular/core';
|
||||
import { ApiConfigService } from '../core/config/api-config.service';
|
||||
import { LocationService } from '../services/location.service';
|
||||
import { LanguageService } from '../services/language.service';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
/** Map internal language codes to API header values */
|
||||
const LANG_HEADER_MAP: Record<string, string> = {
|
||||
@@ -39,7 +39,8 @@ function getAnonymousSessionId(): string {
|
||||
}
|
||||
|
||||
export const apiHeadersInterceptor: HttpInterceptorFn = (req, next) => {
|
||||
if (!req.url.startsWith(environment.apiUrl)) {
|
||||
const apiConfig = inject(ApiConfigService);
|
||||
if (!apiConfig.isApiRequest(req.url)) {
|
||||
return next(req);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user