changes for md

This commit is contained in:
sdarbinyan
2026-02-28 17:42:36 +04:00
parent 377da22761
commit 350581cbe9
4 changed files with 1363 additions and 139 deletions

View File

@@ -4,6 +4,7 @@ import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { routes } from './app.routes';
import { cacheInterceptor } from './interceptors/cache.interceptor';
import { apiHeadersInterceptor } from './interceptors/api-headers.interceptor';
import { provideServiceWorker } from '@angular/service-worker';
export const appConfig: ApplicationConfig = {
@@ -15,7 +16,7 @@ export const appConfig: ApplicationConfig = {
withInMemoryScrolling({ scrollPositionRestoration: 'top' })
),
provideHttpClient(
withInterceptors([cacheInterceptor])
withInterceptors([apiHeadersInterceptor, cacheInterceptor])
),
provideServiceWorker('ngsw-worker.js', {
enabled: !isDevMode(),

View File

@@ -0,0 +1,37 @@
import { HttpInterceptorFn } from '@angular/common/http';
import { inject } from '@angular/core';
import { LocationService } from '../services/location.service';
import { LanguageService } from '../services/language.service';
import { environment } from '../../environments/environment';
/**
* Interceptor that attaches X-Region and X-Language headers
* to every outgoing request aimed at our API.
*
* The backend reads these headers to:
* - filter catalog by region
* - return translated content in the requested language
*/
export const apiHeadersInterceptor: HttpInterceptorFn = (req, next) => {
// Only attach headers to our own API requests
if (!req.url.startsWith(environment.apiUrl)) {
return next(req);
}
const locationService = inject(LocationService);
const languageService = inject(LanguageService);
const regionId = locationService.regionId(); // '' when global
const lang = languageService.currentLanguage(); // 'ru' | 'en' | 'hy'
let headers = req.headers;
if (regionId) {
headers = headers.set('X-Region', regionId);
}
if (lang) {
headers = headers.set('X-Language', lang);
}
return next(req.clone({ headers }));
};