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 }));
|
||||
};
|
||||
Reference in New Issue
Block a user