Compare commits
7 Commits
feat/mater
...
3cbcec5f53
| Author | SHA1 | Date | |
|---|---|---|---|
| 3cbcec5f53 | |||
|
|
8835175fb3 | ||
| 28c3abdb4a | |||
| b30bfc9293 | |||
| d70423fcc0 | |||
| 1b7c0c48e7 | |||
|
|
cb86137730 |
@@ -62,6 +62,12 @@ public class PublicShopController {
|
|||||||
return ResponseEntity.ok(publicShopCatalogService.getProductByPublicPath(publicPath, lang));
|
return ResponseEntity.ok(publicShopCatalogService.getProductByPublicPath(publicPath, lang));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/products/by-id-prefix/{idPrefix}")
|
||||||
|
public ResponseEntity<ShopProductDetailDto> getProductByIdPrefix(@PathVariable String idPrefix,
|
||||||
|
@RequestParam(required = false) String lang) {
|
||||||
|
return ResponseEntity.ok(publicShopCatalogService.getProductByIdPrefix(idPrefix, lang));
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/products/{slug}/model")
|
@GetMapping("/products/{slug}/model")
|
||||||
public ResponseEntity<Resource> getProductModel(@PathVariable String slug) throws IOException {
|
public ResponseEntity<Resource> getProductModel(@PathVariable String slug) throws IOException {
|
||||||
PublicShopCatalogService.ProductModelDownload model = publicShopCatalogService.getProductModelDownload(slug);
|
PublicShopCatalogService.ProductModelDownload model = publicShopCatalogService.getProductModelDownload(slug);
|
||||||
|
|||||||
@@ -163,6 +163,28 @@ public class PublicShopCatalogService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ShopProductDetailDto getProductByIdPrefix(String idPrefix, String language) {
|
||||||
|
String normalizedLanguage = normalizeLanguage(language);
|
||||||
|
String normalizedIdPrefix = normalizeProductIdPrefix(idPrefix);
|
||||||
|
if (normalizedIdPrefix == null) {
|
||||||
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Product not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
CategoryContext categoryContext = loadCategoryContext(normalizedLanguage);
|
||||||
|
PublicProductContext productContext = loadPublicProductContext(categoryContext, normalizedLanguage);
|
||||||
|
ProductEntry entry = requirePublicProductEntry(
|
||||||
|
productContext.entriesByIdPrefix().get(normalizedIdPrefix),
|
||||||
|
categoryContext
|
||||||
|
);
|
||||||
|
|
||||||
|
return toProductDetailDto(
|
||||||
|
entry,
|
||||||
|
productContext.productMediaBySlug(),
|
||||||
|
productContext.variantColorHexByMaterialAndColor(),
|
||||||
|
normalizedLanguage
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public ProductModelDownload getProductModelDownload(String slug) {
|
public ProductModelDownload getProductModelDownload(String slug) {
|
||||||
CategoryContext categoryContext = loadCategoryContext(null);
|
CategoryContext categoryContext = loadCategoryContext(null);
|
||||||
PublicProductContext productContext = loadPublicProductContext(categoryContext, null);
|
PublicProductContext productContext = loadPublicProductContext(categoryContext, null);
|
||||||
@@ -231,11 +253,19 @@ public class PublicShopCatalogService {
|
|||||||
(left, right) -> left,
|
(left, right) -> left,
|
||||||
LinkedHashMap::new
|
LinkedHashMap::new
|
||||||
));
|
));
|
||||||
|
Map<String, ProductEntry> entriesByIdPrefix = entries.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
entry -> normalizeProductIdPrefix(ShopPublicPathSupport.productIdPrefix(entry.product().getId())),
|
||||||
|
entry -> entry,
|
||||||
|
(left, right) -> left,
|
||||||
|
LinkedHashMap::new
|
||||||
|
));
|
||||||
|
|
||||||
return new PublicProductContext(
|
return new PublicProductContext(
|
||||||
entries,
|
entries,
|
||||||
entriesBySlug,
|
entriesBySlug,
|
||||||
entriesByPublicPath,
|
entriesByPublicPath,
|
||||||
|
entriesByIdPrefix,
|
||||||
productMediaBySlug,
|
productMediaBySlug,
|
||||||
variantColorHexByMaterialAndColor
|
variantColorHexByMaterialAndColor
|
||||||
);
|
);
|
||||||
@@ -566,6 +596,15 @@ public class PublicShopCatalogService {
|
|||||||
return normalized.toLowerCase(Locale.ROOT);
|
return normalized.toLowerCase(Locale.ROOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String normalizeProductIdPrefix(String idPrefix) {
|
||||||
|
String normalized = trimToNull(idPrefix);
|
||||||
|
if (normalized == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
normalized = normalized.toLowerCase(Locale.ROOT);
|
||||||
|
return normalized.matches("^[0-9a-f]{8}$") ? normalized : null;
|
||||||
|
}
|
||||||
|
|
||||||
private String trimToNull(String value) {
|
private String trimToNull(String value) {
|
||||||
String raw = String.valueOf(value == null ? "" : value).trim();
|
String raw = String.valueOf(value == null ? "" : value).trim();
|
||||||
if (raw.isEmpty()) {
|
if (raw.isEmpty()) {
|
||||||
@@ -662,6 +701,7 @@ public class PublicShopCatalogService {
|
|||||||
List<ProductEntry> entries,
|
List<ProductEntry> entries,
|
||||||
Map<String, ProductEntry> entriesBySlug,
|
Map<String, ProductEntry> entriesBySlug,
|
||||||
Map<String, ProductEntry> entriesByPublicPath,
|
Map<String, ProductEntry> entriesByPublicPath,
|
||||||
|
Map<String, ProductEntry> entriesByIdPrefix,
|
||||||
Map<String, List<PublicMediaUsageDto>> productMediaBySlug,
|
Map<String, List<PublicMediaUsageDto>> productMediaBySlug,
|
||||||
Map<String, String> variantColorHexByMaterialAndColor
|
Map<String, String> variantColorHexByMaterialAndColor
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -108,6 +108,21 @@ class PublicShopCatalogServiceTest {
|
|||||||
assertEquals("/en/shop/p/12345678-bike-wall-hanger", response.localizedPaths().get("en"));
|
assertEquals("/en/shop/p/12345678-bike-wall-hanger", response.localizedPaths().get("en"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getProductByIdPrefix_shouldResolveLocalizedProduct() {
|
||||||
|
ShopCategory category = buildCategory();
|
||||||
|
ShopProduct product = buildProduct(category);
|
||||||
|
ShopProductVariant variant = buildVariant(product);
|
||||||
|
|
||||||
|
stubPublicCatalog(category, product, variant);
|
||||||
|
|
||||||
|
ShopProductDetailDto response = service.getProductByIdPrefix("12345678", "de");
|
||||||
|
|
||||||
|
assertEquals("bike-wall-hanger", response.slug());
|
||||||
|
assertEquals("12345678-bike-wall-hanger", response.publicPath());
|
||||||
|
assertEquals("/de/shop/p/12345678-bike-wall-hanger", response.localizedPaths().get("de"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getProductByPublicPath_shouldRejectNonCanonicalSegment() {
|
void getProductByPublicPath_shouldRejectNonCanonicalSegment() {
|
||||||
ShopCategory category = buildCategory();
|
ShopCategory category = buildCategory();
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ services:
|
|||||||
container_name: print-calculator-frontend-${ENV}
|
container_name: print-calculator-frontend-${ENV}
|
||||||
ports:
|
ports:
|
||||||
- "${FRONTEND_PORT}:80"
|
- "${FRONTEND_PORT}:80"
|
||||||
|
environment:
|
||||||
|
- SSR_INTERNAL_API_ORIGIN=http://backend:8000
|
||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
- backend
|
||||||
restart: always
|
restart: always
|
||||||
|
|||||||
@@ -8,11 +8,19 @@ import { REQUEST } from '@angular/core';
|
|||||||
import { provideHttpClient, withInterceptors } from '@angular/common/http';
|
import { provideHttpClient, withInterceptors } from '@angular/common/http';
|
||||||
import { serverOriginInterceptor } from './server-origin.interceptor';
|
import { serverOriginInterceptor } from './server-origin.interceptor';
|
||||||
|
|
||||||
|
type TestGlobal = typeof globalThis & {
|
||||||
|
__SSR_INTERNAL_API_ORIGIN__?: string;
|
||||||
|
};
|
||||||
|
|
||||||
describe('serverOriginInterceptor', () => {
|
describe('serverOriginInterceptor', () => {
|
||||||
let http: HttpClient;
|
let http: HttpClient;
|
||||||
let httpMock: HttpTestingController;
|
let httpMock: HttpTestingController;
|
||||||
|
const testGlobal = globalThis as TestGlobal;
|
||||||
|
const originalInternalApiOrigin = testGlobal.__SSR_INTERNAL_API_ORIGIN__;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
delete testGlobal.__SSR_INTERNAL_API_ORIGIN__;
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
provideHttpClient(withInterceptors([serverOriginInterceptor])),
|
provideHttpClient(withInterceptors([serverOriginInterceptor])),
|
||||||
@@ -21,6 +29,7 @@ describe('serverOriginInterceptor', () => {
|
|||||||
provide: REQUEST,
|
provide: REQUEST,
|
||||||
useValue: {
|
useValue: {
|
||||||
protocol: 'https',
|
protocol: 'https',
|
||||||
|
url: '/de/shop/p/91823f84-bike-wall-hanger',
|
||||||
headers: {
|
headers: {
|
||||||
host: 'dev.3d-fab.ch',
|
host: 'dev.3d-fab.ch',
|
||||||
authorization: 'Basic dGVzdDp0ZXN0',
|
authorization: 'Basic dGVzdDp0ZXN0',
|
||||||
@@ -38,6 +47,11 @@ describe('serverOriginInterceptor', () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
httpMock.verify();
|
httpMock.verify();
|
||||||
|
if (originalInternalApiOrigin) {
|
||||||
|
testGlobal.__SSR_INTERNAL_API_ORIGIN__ = originalInternalApiOrigin;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delete testGlobal.__SSR_INTERNAL_API_ORIGIN__;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rewrites relative SSR URLs to the incoming origin and forwards auth headers', () => {
|
it('rewrites relative SSR URLs to the incoming origin and forwards auth headers', () => {
|
||||||
@@ -74,4 +88,109 @@ describe('serverOriginInterceptor', () => {
|
|||||||
expect(request.request.headers.get('cookie')).toBe('session=abc123');
|
expect(request.request.headers.get('cookie')).toBe('session=abc123');
|
||||||
request.flush({});
|
request.flush({});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('uses the internal SSR API origin for public shop discovery calls', () => {
|
||||||
|
testGlobal.__SSR_INTERNAL_API_ORIGIN__ = 'http://backend:8000/';
|
||||||
|
|
||||||
|
http.get('/api/shop/products/by-id-prefix/91823f84?lang=de').subscribe();
|
||||||
|
|
||||||
|
const request = httpMock.expectOne(
|
||||||
|
'http://backend:8000/api/shop/products/by-id-prefix/91823f84?lang=de',
|
||||||
|
);
|
||||||
|
expect(request.request.headers.get('authorization')).toBe(
|
||||||
|
'Basic dGVzdDp0ZXN0',
|
||||||
|
);
|
||||||
|
expect(request.request.headers.get('cookie')).toBe('session=abc123');
|
||||||
|
expect(request.request.headers.get('accept-language')).toBe(
|
||||||
|
'de-CH,de;q=0.9,en;q=0.8',
|
||||||
|
);
|
||||||
|
request.flush({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('bypasses the public origin even when the proxy strips authorization on shop SSR requests', () => {
|
||||||
|
testGlobal.__SSR_INTERNAL_API_ORIGIN__ = 'http://backend:8000/';
|
||||||
|
|
||||||
|
TestBed.resetTestingModule();
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
provideHttpClient(withInterceptors([serverOriginInterceptor])),
|
||||||
|
provideHttpClientTesting(),
|
||||||
|
{
|
||||||
|
provide: REQUEST,
|
||||||
|
useValue: {
|
||||||
|
protocol: 'https',
|
||||||
|
url: '/de/shop/p/91823f84-bike-wall-hanger',
|
||||||
|
headers: {
|
||||||
|
host: 'dev.3d-fab.ch',
|
||||||
|
cookie: 'session=abc123',
|
||||||
|
'accept-language': 'de-CH,de;q=0.9,en;q=0.8',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
http = TestBed.inject(HttpClient);
|
||||||
|
httpMock = TestBed.inject(HttpTestingController);
|
||||||
|
|
||||||
|
http.get('/api/shop/products/by-id-prefix/91823f84?lang=de').subscribe();
|
||||||
|
|
||||||
|
const request = httpMock.expectOne(
|
||||||
|
'http://backend:8000/api/shop/products/by-id-prefix/91823f84?lang=de',
|
||||||
|
);
|
||||||
|
expect(request.request.headers.get('authorization')).toBeNull();
|
||||||
|
expect(request.request.headers.get('cookie')).toBe('session=abc123');
|
||||||
|
expect(request.request.headers.get('accept-language')).toBe(
|
||||||
|
'de-CH,de;q=0.9,en;q=0.8',
|
||||||
|
);
|
||||||
|
request.flush({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps transactional shop API calls on the public origin', () => {
|
||||||
|
testGlobal.__SSR_INTERNAL_API_ORIGIN__ = 'http://backend:8000/';
|
||||||
|
|
||||||
|
http.get('/api/shop/cart').subscribe();
|
||||||
|
|
||||||
|
const request = httpMock.expectOne('https://dev.3d-fab.ch/api/shop/cart');
|
||||||
|
expect(request.request.headers.get('authorization')).toBe(
|
||||||
|
'Basic dGVzdDp0ZXN0',
|
||||||
|
);
|
||||||
|
request.flush({});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps non-shop pages on the public origin even for public shop APIs', () => {
|
||||||
|
testGlobal.__SSR_INTERNAL_API_ORIGIN__ = 'http://backend:8000/';
|
||||||
|
|
||||||
|
TestBed.resetTestingModule();
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
provideHttpClient(withInterceptors([serverOriginInterceptor])),
|
||||||
|
provideHttpClientTesting(),
|
||||||
|
{
|
||||||
|
provide: REQUEST,
|
||||||
|
useValue: {
|
||||||
|
protocol: 'https',
|
||||||
|
url: '/de/checkout?session=abc',
|
||||||
|
headers: {
|
||||||
|
host: 'dev.3d-fab.ch',
|
||||||
|
cookie: 'session=abc123',
|
||||||
|
'accept-language': 'de-CH,de;q=0.9,en;q=0.8',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
http = TestBed.inject(HttpClient);
|
||||||
|
httpMock = TestBed.inject(HttpTestingController);
|
||||||
|
|
||||||
|
http.get('/api/shop/products/by-id-prefix/91823f84?lang=de').subscribe();
|
||||||
|
|
||||||
|
const request = httpMock.expectOne(
|
||||||
|
'https://dev.3d-fab.ch/api/shop/products/by-id-prefix/91823f84?lang=de',
|
||||||
|
);
|
||||||
|
expect(request.request.headers.get('authorization')).toBeNull();
|
||||||
|
expect(request.request.headers.get('cookie')).toBe('session=abc123');
|
||||||
|
request.flush({});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,12 +5,27 @@ import {
|
|||||||
resolveRequestOrigin,
|
resolveRequestOrigin,
|
||||||
} from '../../../core/request-origin';
|
} from '../../../core/request-origin';
|
||||||
|
|
||||||
|
type ServerRequestLike = RequestLike & {
|
||||||
|
originalUrl?: string;
|
||||||
|
url?: string;
|
||||||
|
};
|
||||||
|
|
||||||
const FORWARDED_REQUEST_HEADERS = [
|
const FORWARDED_REQUEST_HEADERS = [
|
||||||
'authorization',
|
'authorization',
|
||||||
'cookie',
|
'cookie',
|
||||||
'accept-language',
|
'accept-language',
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
|
const SHOP_DISCOVERY_API_PATTERNS = [
|
||||||
|
/^\/api\/shop\/categories(?:\/[^/?#]+)?$/i,
|
||||||
|
/^\/api\/shop\/products$/i,
|
||||||
|
/^\/api\/shop\/products\/by-id-prefix\/[^/?#]+$/i,
|
||||||
|
/^\/api\/shop\/products\/by-path\/[^/?#]+$/i,
|
||||||
|
/^\/api\/shop\/products\/[^/?#]+$/i,
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
const SHOP_PAGE_PATH_PATTERN = /^\/(?:it|en|de|fr)\/shop(?:\/.*)?$/i;
|
||||||
|
|
||||||
function isAbsoluteUrl(url: string): boolean {
|
function isAbsoluteUrl(url: string): boolean {
|
||||||
return /^[a-z][a-z\d+\-.]*:/i.test(url) || url.startsWith('//');
|
return /^[a-z][a-z\d+\-.]*:/i.test(url) || url.startsWith('//');
|
||||||
}
|
}
|
||||||
@@ -20,6 +35,14 @@ function normalizeRelativePath(url: string): string {
|
|||||||
return withoutDot.startsWith('/') ? withoutDot : `/${withoutDot}`;
|
return withoutDot.startsWith('/') ? withoutDot : `/${withoutDot}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stripQueryAndHash(url: string): string {
|
||||||
|
return String(url ?? '').split(/[?#]/, 1)[0] || '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeOrigin(origin: string): string {
|
||||||
|
return origin.replace(/\/+$/, '');
|
||||||
|
}
|
||||||
|
|
||||||
function readRequestHeader(
|
function readRequestHeader(
|
||||||
request: RequestLike | null,
|
request: RequestLike | null,
|
||||||
name: (typeof FORWARDED_REQUEST_HEADERS)[number],
|
name: (typeof FORWARDED_REQUEST_HEADERS)[number],
|
||||||
@@ -34,18 +57,95 @@ function readRequestHeader(
|
|||||||
return typeof headerValue === 'string' ? headerValue : null;
|
return typeof headerValue === 'string' ? headerValue : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readRequestPath(request: ServerRequestLike | null): string | null {
|
||||||
|
const rawPath =
|
||||||
|
(typeof request?.originalUrl === 'string' && request.originalUrl) ||
|
||||||
|
(typeof request?.url === 'string' && request.url) ||
|
||||||
|
null;
|
||||||
|
if (!rawPath) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAbsoluteUrl(rawPath)) {
|
||||||
|
try {
|
||||||
|
return stripQueryAndHash(new URL(rawPath).pathname || '/');
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stripQueryAndHash(rawPath.startsWith('/') ? rawPath : `/${rawPath}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPublicShopPageRequest(request: ServerRequestLike | null): boolean {
|
||||||
|
const requestPath = readRequestPath(request);
|
||||||
|
return !!requestPath && SHOP_PAGE_PATH_PATTERN.test(requestPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPublicShopDiscoveryApi(url: string): boolean {
|
||||||
|
const normalizedPath = stripQueryAndHash(normalizeRelativePath(url));
|
||||||
|
return SHOP_DISCOVERY_API_PATTERNS.some((pattern) =>
|
||||||
|
pattern.test(normalizedPath),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function readInternalApiOrigin(): string | null {
|
||||||
|
const globalObject = globalThis as {
|
||||||
|
__SSR_INTERNAL_API_ORIGIN__?: string;
|
||||||
|
process?: {
|
||||||
|
env?: Record<string, string | undefined>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
const explicitOverride =
|
||||||
|
typeof globalObject.__SSR_INTERNAL_API_ORIGIN__ === 'string'
|
||||||
|
? globalObject.__SSR_INTERNAL_API_ORIGIN__
|
||||||
|
: null;
|
||||||
|
const env = (
|
||||||
|
globalObject as {
|
||||||
|
process?: {
|
||||||
|
env?: Record<string, string | undefined>;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
).process?.env;
|
||||||
|
const rawValue = explicitOverride ?? env?.['SSR_INTERNAL_API_ORIGIN'];
|
||||||
|
if (typeof rawValue !== 'string') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalized = rawValue.trim();
|
||||||
|
return normalized ? normalizeOrigin(normalized) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveApiOrigin(
|
||||||
|
request: ServerRequestLike | null,
|
||||||
|
relativeUrl: string,
|
||||||
|
): string | null {
|
||||||
|
const internalOrigin = readInternalApiOrigin();
|
||||||
|
if (
|
||||||
|
internalOrigin &&
|
||||||
|
isPublicShopPageRequest(request) &&
|
||||||
|
isPublicShopDiscoveryApi(relativeUrl)
|
||||||
|
) {
|
||||||
|
return internalOrigin;
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolveRequestOrigin(request);
|
||||||
|
}
|
||||||
|
|
||||||
export const serverOriginInterceptor: HttpInterceptorFn = (req, next) => {
|
export const serverOriginInterceptor: HttpInterceptorFn = (req, next) => {
|
||||||
if (isAbsoluteUrl(req.url)) {
|
if (isAbsoluteUrl(req.url)) {
|
||||||
return next(req);
|
return next(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
const request = inject(REQUEST, { optional: true }) as RequestLike | null;
|
const request = inject(REQUEST, {
|
||||||
const origin = resolveRequestOrigin(request);
|
optional: true,
|
||||||
|
}) as ServerRequestLike | null;
|
||||||
|
const origin = resolveApiOrigin(request, req.url);
|
||||||
if (!origin) {
|
if (!origin) {
|
||||||
return next(req);
|
return next(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
const absoluteUrl = `${origin}${normalizeRelativePath(req.url)}`;
|
const absoluteUrl = `${normalizeOrigin(origin)}${normalizeRelativePath(req.url)}`;
|
||||||
const forwardedHeaders = FORWARDED_REQUEST_HEADERS.reduce<
|
const forwardedHeaders = FORWARDED_REQUEST_HEADERS.reduce<
|
||||||
Record<string, string>
|
Record<string, string>
|
||||||
>((headers, name) => {
|
>((headers, name) => {
|
||||||
|
|||||||
@@ -71,7 +71,13 @@ describe('ProductDetailComponent', () => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function createComponent(routerUrl = '/de/shop/p/91823f84-bike-wall-hanger') {
|
function createComponent(
|
||||||
|
routerUrl = '/de/shop/p/91823f84-bike-wall-hanger',
|
||||||
|
options?: {
|
||||||
|
currentLang?: 'it' | 'en' | 'de' | 'fr';
|
||||||
|
selectedLang?: 'it' | 'en' | 'de' | 'fr';
|
||||||
|
},
|
||||||
|
) {
|
||||||
const responseInit: { status?: number } = {};
|
const responseInit: { status?: number } = {};
|
||||||
const seoService = jasmine.createSpyObj<SeoService>('SeoService', [
|
const seoService = jasmine.createSpyObj<SeoService>('SeoService', [
|
||||||
'applyResolvedSeo',
|
'applyResolvedSeo',
|
||||||
@@ -93,11 +99,15 @@ describe('ProductDetailComponent', () => {
|
|||||||
return translations[key] ?? key;
|
return translations[key] ?? key;
|
||||||
});
|
});
|
||||||
|
|
||||||
const currentLang = signal<'it' | 'en' | 'de' | 'fr'>('de');
|
const currentLang = signal<'it' | 'en' | 'de' | 'fr'>(
|
||||||
|
options?.currentLang ?? 'de',
|
||||||
|
);
|
||||||
const languageService = {
|
const languageService = {
|
||||||
currentLang,
|
currentLang,
|
||||||
selectedLang: () => currentLang(),
|
selectedLang: () => options?.selectedLang ?? currentLang(),
|
||||||
setLocalizedRouteOverrides: jasmine.createSpy('setLocalizedRouteOverrides'),
|
setLocalizedRouteOverrides: jasmine.createSpy(
|
||||||
|
'setLocalizedRouteOverrides',
|
||||||
|
),
|
||||||
clearLocalizedRouteOverrides: jasmine.createSpy(
|
clearLocalizedRouteOverrides: jasmine.createSpy(
|
||||||
'clearLocalizedRouteOverrides',
|
'clearLocalizedRouteOverrides',
|
||||||
),
|
),
|
||||||
@@ -113,7 +123,9 @@ describe('ProductDetailComponent', () => {
|
|||||||
.createSpy('quantityForVariant')
|
.createSpy('quantityForVariant')
|
||||||
.and.returnValue(0),
|
.and.returnValue(0),
|
||||||
loadCart: jasmine.createSpy('loadCart').and.returnValue(of(null)),
|
loadCart: jasmine.createSpy('loadCart').and.returnValue(of(null)),
|
||||||
resolveMediaUrl: jasmine.createSpy('resolveMediaUrl').and.returnValue(null),
|
resolveMediaUrl: jasmine
|
||||||
|
.createSpy('resolveMediaUrl')
|
||||||
|
.and.returnValue(null),
|
||||||
};
|
};
|
||||||
|
|
||||||
const router = {
|
const router = {
|
||||||
@@ -126,9 +138,13 @@ describe('ProductDetailComponent', () => {
|
|||||||
} as unknown as Router;
|
} as unknown as Router;
|
||||||
|
|
||||||
const activatedRoute = {
|
const activatedRoute = {
|
||||||
paramMap: of(convertToParamMap({ productSlug: '91823f84-bike-wall-hanger' })),
|
paramMap: of(
|
||||||
|
convertToParamMap({ productSlug: '91823f84-bike-wall-hanger' }),
|
||||||
|
),
|
||||||
snapshot: {
|
snapshot: {
|
||||||
paramMap: convertToParamMap({ productSlug: '91823f84-bike-wall-hanger' }),
|
paramMap: convertToParamMap({
|
||||||
|
productSlug: '91823f84-bike-wall-hanger',
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
} as unknown as ActivatedRoute;
|
} as unknown as ActivatedRoute;
|
||||||
|
|
||||||
@@ -185,6 +201,21 @@ describe('ProductDetailComponent', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('uses the route language for canonical SEO even if the selected translation language lags', () => {
|
||||||
|
const { component, seoService } = createComponent(undefined, {
|
||||||
|
currentLang: 'de',
|
||||||
|
selectedLang: 'en',
|
||||||
|
});
|
||||||
|
|
||||||
|
(component as any).applySeo(buildProduct());
|
||||||
|
|
||||||
|
expect(seoService.applyResolvedSeo).toHaveBeenCalledWith(
|
||||||
|
jasmine.objectContaining({
|
||||||
|
canonicalPath: '/de/shop/p/91823f84-bike-wall-hanger',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('applies noindex for products explicitly marked as non-indexable', () => {
|
it('applies noindex for products explicitly marked as non-indexable', () => {
|
||||||
const { component, seoService } = createComponent();
|
const { component, seoService } = createComponent();
|
||||||
|
|
||||||
@@ -200,7 +231,9 @@ describe('ProductDetailComponent', () => {
|
|||||||
it('builds a soft SSR fallback with 200 + index follow', () => {
|
it('builds a soft SSR fallback with 200 + index follow', () => {
|
||||||
const { component, seoService, responseInit } = createComponent();
|
const { component, seoService, responseInit } = createComponent();
|
||||||
|
|
||||||
expect((component as any).shouldUseSoftSeoFallback({ status: 500 })).toBeTrue();
|
expect(
|
||||||
|
(component as any).shouldUseSoftSeoFallback({ status: 500 }),
|
||||||
|
).toBeTrue();
|
||||||
(component as any).setResponseStatus(200);
|
(component as any).setResponseStatus(200);
|
||||||
(component as any).applySoftFallbackSeo('91823f84-bike-wall-hanger');
|
(component as any).applySoftFallbackSeo('91823f84-bike-wall-hanger');
|
||||||
|
|
||||||
@@ -221,7 +254,9 @@ describe('ProductDetailComponent', () => {
|
|||||||
it('keeps hard fallback noindex for missing products', () => {
|
it('keeps hard fallback noindex for missing products', () => {
|
||||||
const { component, seoService, responseInit } = createComponent();
|
const { component, seoService, responseInit } = createComponent();
|
||||||
|
|
||||||
expect((component as any).shouldUseSoftSeoFallback({ status: 404 })).toBeFalse();
|
expect(
|
||||||
|
(component as any).shouldUseSoftSeoFallback({ status: 404 }),
|
||||||
|
).toBeFalse();
|
||||||
(component as any).setResponseStatus(404);
|
(component as any).setResponseStatus(404);
|
||||||
(component as any).applyHardFallbackSeo();
|
(component as any).applyHardFallbackSeo();
|
||||||
|
|
||||||
|
|||||||
@@ -254,37 +254,35 @@ export class ProductDetailComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const productSlug = routeParams.productSlug as string;
|
const productSlug = routeParams.productSlug as string;
|
||||||
return this.shopService
|
return this.shopService.getProductByPublicPath(productSlug).pipe(
|
||||||
.getProductByPublicPath(productSlug)
|
catchError((error) => {
|
||||||
.pipe(
|
this.languageService.clearLocalizedRouteOverrides();
|
||||||
catchError((error) => {
|
this.product.set(null);
|
||||||
this.languageService.clearLocalizedRouteOverrides();
|
this.selectedVariantId.set(null);
|
||||||
this.product.set(null);
|
this.setSelectedImageAssetId(null);
|
||||||
this.selectedVariantId.set(null);
|
this.modelFile.set(null);
|
||||||
this.setSelectedImageAssetId(null);
|
const isNotFound = error?.status === 404;
|
||||||
this.modelFile.set(null);
|
if (isNotFound) {
|
||||||
const isNotFound = error?.status === 404;
|
this.error.set('SHOP.NOT_FOUND');
|
||||||
if (isNotFound) {
|
this.setResponseStatus(404);
|
||||||
this.error.set('SHOP.NOT_FOUND');
|
this.applyHardFallbackSeo();
|
||||||
this.setResponseStatus(404);
|
|
||||||
this.applyHardFallbackSeo();
|
|
||||||
return of(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.shouldUseSoftSeoFallback(error)) {
|
|
||||||
this.error.set(null);
|
|
||||||
this.softFallbackActive.set(true);
|
|
||||||
this.setResponseStatus(200);
|
|
||||||
this.applySoftFallbackSeo(productSlug);
|
|
||||||
return of(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.error.set('SHOP.LOAD_ERROR');
|
|
||||||
this.setResponseStatus(503);
|
|
||||||
return of(null);
|
return of(null);
|
||||||
}),
|
}
|
||||||
finalize(() => this.loading.set(false)),
|
|
||||||
);
|
if (this.shouldUseSoftSeoFallback(error)) {
|
||||||
|
this.error.set(null);
|
||||||
|
this.softFallbackActive.set(true);
|
||||||
|
this.setResponseStatus(200);
|
||||||
|
this.applySoftFallbackSeo(productSlug);
|
||||||
|
return of(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.error.set('SHOP.LOAD_ERROR');
|
||||||
|
this.setResponseStatus(503);
|
||||||
|
return of(null);
|
||||||
|
}),
|
||||||
|
finalize(() => this.loading.set(false)),
|
||||||
|
);
|
||||||
}),
|
}),
|
||||||
takeUntilDestroyed(this.destroyRef),
|
takeUntilDestroyed(this.destroyRef),
|
||||||
)
|
)
|
||||||
@@ -607,7 +605,7 @@ export class ProductDetailComponent {
|
|||||||
this.translate.instant('SHOP.CATALOG_META_DESCRIPTION');
|
this.translate.instant('SHOP.CATALOG_META_DESCRIPTION');
|
||||||
const robots =
|
const robots =
|
||||||
product.indexable === false ? 'noindex, nofollow' : 'index, follow';
|
product.indexable === false ? 'noindex, nofollow' : 'index, follow';
|
||||||
const lang = this.languageService.selectedLang();
|
const lang = this.languageService.currentLang();
|
||||||
const canonicalPath =
|
const canonicalPath =
|
||||||
product.localizedPaths?.[lang] ?? product.localizedPaths?.it ?? null;
|
product.localizedPaths?.[lang] ?? product.localizedPaths?.it ?? null;
|
||||||
|
|
||||||
@@ -859,7 +857,7 @@ export class ProductDetailComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const currentTree = this.router.parseUrl(this.router.url);
|
const currentTree = this.router.parseUrl(this.router.url);
|
||||||
const lang = this.languageService.selectedLang();
|
const lang = this.languageService.currentLang();
|
||||||
const targetPath =
|
const targetPath =
|
||||||
product.localizedPaths?.[lang] ??
|
product.localizedPaths?.[lang] ??
|
||||||
`/${lang}/shop/p/${this.shopRouteService.productPathSegment(product)}`;
|
`/${lang}/shop/p/${this.shopRouteService.productPathSegment(product)}`;
|
||||||
@@ -904,9 +902,7 @@ export class ProductDetailComponent {
|
|||||||
return this.normalizeRouteParam(this.route.snapshot.paramMap.get(name));
|
return this.normalizeRouteParam(this.route.snapshot.paramMap.get(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
private normalizeRouteParam(
|
private normalizeRouteParam(value: string | null | undefined): string | null {
|
||||||
value: string | null | undefined,
|
|
||||||
): string | null {
|
|
||||||
const normalized = String(value ?? '').trim();
|
const normalized = String(value ?? '').trim();
|
||||||
return normalized || null;
|
return normalized || null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { signal } from '@angular/core';
|
||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import {
|
import {
|
||||||
HttpClientTestingModule,
|
HttpClientTestingModule,
|
||||||
@@ -13,6 +14,11 @@ import { LanguageService } from '../../../core/services/language.service';
|
|||||||
describe('ShopService', () => {
|
describe('ShopService', () => {
|
||||||
let service: ShopService;
|
let service: ShopService;
|
||||||
let httpMock: HttpTestingController;
|
let httpMock: HttpTestingController;
|
||||||
|
const currentLang = signal<'it' | 'en' | 'de' | 'fr'>('it');
|
||||||
|
const languageService = {
|
||||||
|
currentLang,
|
||||||
|
selectedLang: jasmine.createSpy('selectedLang').and.returnValue('it'),
|
||||||
|
};
|
||||||
|
|
||||||
const buildCart = (): ShopCartResponse => ({
|
const buildCart = (): ShopCartResponse => ({
|
||||||
session: {
|
session: {
|
||||||
@@ -131,13 +137,14 @@ describe('ShopService', () => {
|
|||||||
ShopService,
|
ShopService,
|
||||||
{
|
{
|
||||||
provide: LanguageService,
|
provide: LanguageService,
|
||||||
useValue: {
|
useValue: languageService,
|
||||||
selectedLang: () => 'it',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
currentLang.set('it');
|
||||||
|
languageService.selectedLang.and.returnValue('it');
|
||||||
|
|
||||||
service = TestBed.inject(ShopService);
|
service = TestBed.inject(ShopService);
|
||||||
httpMock = TestBed.inject(HttpTestingController);
|
httpMock = TestBed.inject(HttpTestingController);
|
||||||
});
|
});
|
||||||
@@ -196,7 +203,7 @@ describe('ShopService', () => {
|
|||||||
return (
|
return (
|
||||||
request.method === 'GET' &&
|
request.method === 'GET' &&
|
||||||
request.url ===
|
request.url ===
|
||||||
'http://localhost:8000/api/shop/products/by-path/12345678-supporto-cavo-scrivania' &&
|
'http://localhost:8000/api/shop/products/by-id-prefix/12345678' &&
|
||||||
request.params.get('lang') === 'it'
|
request.params.get('lang') === 'it'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -206,47 +213,76 @@ describe('ShopService', () => {
|
|||||||
expect(response?.name).toBe('Supporto cavo scrivania');
|
expect(response?.name).toBe('Supporto cavo scrivania');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects product paths whose slug tail does not match the canonical path', () => {
|
it('resolves products from the stable uuid prefix even if the slug tail is stale', () => {
|
||||||
let errorResponse: { status?: number } | undefined;
|
let response: ShopProductDetail | undefined;
|
||||||
|
|
||||||
service.getProductByPublicPath('12345678-qualunque-nome').subscribe({
|
service.getProductByPublicPath('12345678-qualunque-nome').subscribe({
|
||||||
next: () => fail('Expected canonical path mismatch to return 404'),
|
next: (product) => {
|
||||||
error: (error) => {
|
response = product;
|
||||||
errorResponse = error;
|
|
||||||
},
|
},
|
||||||
|
error: () =>
|
||||||
|
fail('Expected stale slug tails to resolve from the uuid prefix'),
|
||||||
});
|
});
|
||||||
|
|
||||||
const request = httpMock.expectOne((request) => {
|
const request = httpMock.expectOne((request) => {
|
||||||
return (
|
return (
|
||||||
request.method === 'GET' &&
|
request.method === 'GET' &&
|
||||||
request.url ===
|
request.url ===
|
||||||
'http://localhost:8000/api/shop/products/by-path/12345678-qualunque-nome' &&
|
'http://localhost:8000/api/shop/products/by-id-prefix/12345678' &&
|
||||||
request.params.get('lang') === 'it'
|
request.params.get('lang') === 'it'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
request.flush('Not found', { status: 404, statusText: 'Not Found' });
|
request.flush(buildProduct());
|
||||||
expect(errorResponse?.status).toBe(404);
|
|
||||||
|
expect(response?.id).toBe('12345678-abcd-4abc-9abc-1234567890ab');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects bare uuid product paths without the localized slug tail', () => {
|
it('resolves bare uuid product paths through the stable uuid prefix endpoint', () => {
|
||||||
let errorResponse: { status?: number } | undefined;
|
let response: ShopProductDetail | undefined;
|
||||||
|
|
||||||
service.getProductByPublicPath('12345678').subscribe({
|
service.getProductByPublicPath('12345678').subscribe({
|
||||||
next: () => fail('Expected bare uuid path to return 404'),
|
next: (product) => {
|
||||||
error: (error) => {
|
response = product;
|
||||||
errorResponse = error;
|
|
||||||
},
|
},
|
||||||
|
error: () =>
|
||||||
|
fail('Expected bare uuid path to resolve from the uuid prefix'),
|
||||||
});
|
});
|
||||||
|
|
||||||
const request = httpMock.expectOne((request) => {
|
const request = httpMock.expectOne((request) => {
|
||||||
return (
|
return (
|
||||||
request.method === 'GET' &&
|
request.method === 'GET' &&
|
||||||
request.url ===
|
request.url ===
|
||||||
'http://localhost:8000/api/shop/products/by-path/12345678' &&
|
'http://localhost:8000/api/shop/products/by-id-prefix/12345678' &&
|
||||||
request.params.get('lang') === 'it'
|
request.params.get('lang') === 'it'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
request.flush('Not found', { status: 404, statusText: 'Not Found' });
|
request.flush(buildProduct());
|
||||||
expect(errorResponse?.status).toBe(404);
|
|
||||||
|
expect(response?.publicPath).toBe('12345678-supporto-cavo-scrivania');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses the route language for public shop lookups when translate.currentLang lags behind', () => {
|
||||||
|
let response: ShopProductDetail | undefined;
|
||||||
|
|
||||||
|
currentLang.set('de');
|
||||||
|
languageService.selectedLang.and.returnValue('en');
|
||||||
|
|
||||||
|
service
|
||||||
|
.getProductByPublicPath('12345678-schreibtisch-kabelhalter')
|
||||||
|
.subscribe((product) => {
|
||||||
|
response = product;
|
||||||
|
});
|
||||||
|
|
||||||
|
const request = httpMock.expectOne((request) => {
|
||||||
|
return (
|
||||||
|
request.method === 'GET' &&
|
||||||
|
request.url ===
|
||||||
|
'http://localhost:8000/api/shop/products/by-id-prefix/12345678' &&
|
||||||
|
request.params.get('lang') === 'de'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
request.flush(buildProduct());
|
||||||
|
|
||||||
|
expect(response?.id).toBe('12345678-abcd-4abc-9abc-1234567890ab');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -290,12 +290,14 @@ export class ShopService {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.http.get<ShopProductDetail>(
|
const productIdPrefix = this.extractProductIdPrefix(normalizedPath);
|
||||||
`${this.apiUrl}/products/by-path/${encodeURIComponent(normalizedPath)}`,
|
const endpoint = productIdPrefix
|
||||||
{
|
? `${this.apiUrl}/products/by-id-prefix/${encodeURIComponent(productIdPrefix)}`
|
||||||
params: this.buildLangParams(),
|
: `${this.apiUrl}/products/by-path/${encodeURIComponent(normalizedPath)}`;
|
||||||
},
|
|
||||||
);
|
return this.http.get<ShopProductDetail>(endpoint, {
|
||||||
|
params: this.buildLangParams(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private normalizePublicPath(value: string | null | undefined): string {
|
private normalizePublicPath(value: string | null | undefined): string {
|
||||||
@@ -304,6 +306,11 @@ export class ShopService {
|
|||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extractProductIdPrefix(value: string): string | null {
|
||||||
|
const match = value.match(/^([0-9a-f]{8})(?:-|$)/);
|
||||||
|
return match?.[1] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
loadCart(): Observable<ShopCartResponse> {
|
loadCart(): Observable<ShopCartResponse> {
|
||||||
this.cartLoading.set(true);
|
this.cartLoading.set(true);
|
||||||
return this.http
|
return this.http
|
||||||
@@ -455,7 +462,10 @@ export class ShopService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private buildLangParams(): HttpParams {
|
private buildLangParams(): HttpParams {
|
||||||
return new HttpParams().set('lang', this.languageService.selectedLang());
|
// Public shop URLs are localized. During direct loads the translation
|
||||||
|
// service can still momentarily reflect the browser language, while the
|
||||||
|
// route language has already been resolved from the URL.
|
||||||
|
return new HttpParams().set('lang', this.languageService.currentLang());
|
||||||
}
|
}
|
||||||
|
|
||||||
private setCart(cart: ShopCartResponse): void {
|
private setCart(cart: ShopCartResponse): void {
|
||||||
|
|||||||
@@ -60,24 +60,26 @@ describe('ShopPageComponent', () => {
|
|||||||
'TranslateService',
|
'TranslateService',
|
||||||
['instant'],
|
['instant'],
|
||||||
);
|
);
|
||||||
translate.instant.and.callFake((key: string, params?: { count?: number }) => {
|
translate.instant.and.callFake(
|
||||||
const translations: Record<string, string> = {
|
(key: string, params?: { count?: number }) => {
|
||||||
'SHOP.TITLE': 'Technische Lösungen',
|
const translations: Record<string, string> = {
|
||||||
'SHOP.SUBTITLE': 'Fertige Produkte, die praktische Probleme lösen',
|
'SHOP.TITLE': 'Technische Lösungen',
|
||||||
'SHOP.CATALOG_TITLE': 'Alle Produkte',
|
'SHOP.SUBTITLE': 'Fertige Produkte, die praktische Probleme lösen',
|
||||||
'SHOP.CATALOG_LABEL': 'Katalog',
|
'SHOP.CATALOG_TITLE': 'Alle Produkte',
|
||||||
'SHOP.SELECTED_CATEGORY': 'Ausgewählte Kategorie',
|
'SHOP.CATALOG_LABEL': 'Katalog',
|
||||||
'SHOP.CATALOG_META_DESCRIPTION':
|
'SHOP.SELECTED_CATEGORY': 'Ausgewählte Kategorie',
|
||||||
'Entdecken Sie 3D-gedruckte Produkte und technisches Zubehör.',
|
'SHOP.CATALOG_META_DESCRIPTION':
|
||||||
'SEO.ROUTES.SHOP.CATEGORY_TITLE': 'Shop-Kategorie | 3D fab',
|
'Entdecken Sie 3D-gedruckte Produkte und technisches Zubehör.',
|
||||||
'SEO.ROUTES.SHOP.CATEGORY_DESCRIPTION':
|
'SEO.ROUTES.SHOP.CATEGORY_TITLE': 'Shop-Kategorie | 3D fab',
|
||||||
'Entdecken Sie Produkte dieser Kategorie und technische Lösungen.',
|
'SEO.ROUTES.SHOP.CATEGORY_DESCRIPTION':
|
||||||
};
|
'Entdecken Sie Produkte dieser Kategorie und technische Lösungen.',
|
||||||
if (key === 'SHOP.CATEGORY_META') {
|
};
|
||||||
return `${params?.count ?? 0} Produkte in dieser Kategorie verfügbar`;
|
if (key === 'SHOP.CATEGORY_META') {
|
||||||
}
|
return `${params?.count ?? 0} Produkte in dieser Kategorie verfügbar`;
|
||||||
return translations[key] ?? key;
|
}
|
||||||
});
|
return translations[key] ?? key;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const currentLang = signal<'it' | 'en' | 'de' | 'fr'>('de');
|
const currentLang = signal<'it' | 'en' | 'de' | 'fr'>('de');
|
||||||
const languageService = {
|
const languageService = {
|
||||||
@@ -100,11 +102,17 @@ describe('ShopPageComponent', () => {
|
|||||||
flattenCategoryTree: jasmine
|
flattenCategoryTree: jasmine
|
||||||
.createSpy('flattenCategoryTree')
|
.createSpy('flattenCategoryTree')
|
||||||
.and.returnValue([]),
|
.and.returnValue([]),
|
||||||
quantityForProduct: jasmine.createSpy('quantityForProduct').and.returnValue(0),
|
quantityForProduct: jasmine
|
||||||
|
.createSpy('quantityForProduct')
|
||||||
|
.and.returnValue(0),
|
||||||
loadCart: jasmine.createSpy('loadCart').and.returnValue(of(null)),
|
loadCart: jasmine.createSpy('loadCart').and.returnValue(of(null)),
|
||||||
clearCart: jasmine.createSpy('clearCart').and.returnValue(of(null)),
|
clearCart: jasmine.createSpy('clearCart').and.returnValue(of(null)),
|
||||||
removeCartItem: jasmine.createSpy('removeCartItem').and.returnValue(of(null)),
|
removeCartItem: jasmine
|
||||||
updateCartItem: jasmine.createSpy('updateCartItem').and.returnValue(of(null)),
|
.createSpy('removeCartItem')
|
||||||
|
.and.returnValue(of(null)),
|
||||||
|
updateCartItem: jasmine
|
||||||
|
.createSpy('updateCartItem')
|
||||||
|
.and.returnValue(of(null)),
|
||||||
};
|
};
|
||||||
|
|
||||||
const router = {
|
const router = {
|
||||||
@@ -164,7 +172,9 @@ describe('ShopPageComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('keeps noindex for categories explicitly marked as non-indexable', () => {
|
it('keeps noindex for categories explicitly marked as non-indexable', () => {
|
||||||
const { component, seoService } = createComponent('/de/shop/compatible-with-garmin');
|
const { component, seoService } = createComponent(
|
||||||
|
'/de/shop/compatible-with-garmin',
|
||||||
|
);
|
||||||
|
|
||||||
(component as any).applySeo(buildCategory({ indexable: false }));
|
(component as any).applySeo(buildCategory({ indexable: false }));
|
||||||
|
|
||||||
@@ -180,7 +190,9 @@ describe('ShopPageComponent', () => {
|
|||||||
'/de/shop/compatible-with-garmin',
|
'/de/shop/compatible-with-garmin',
|
||||||
);
|
);
|
||||||
|
|
||||||
expect((component as any).shouldUseSoftSeoFallback({ status: 500 })).toBeTrue();
|
expect(
|
||||||
|
(component as any).shouldUseSoftSeoFallback({ status: 500 }),
|
||||||
|
).toBeTrue();
|
||||||
(component as any).setResponseStatus(200);
|
(component as any).setResponseStatus(200);
|
||||||
(component as any).applySoftFallbackSeo('compatible-with-garmin');
|
(component as any).applySoftFallbackSeo('compatible-with-garmin');
|
||||||
|
|
||||||
@@ -203,7 +215,9 @@ describe('ShopPageComponent', () => {
|
|||||||
'/de/shop/compatible-with-garmin',
|
'/de/shop/compatible-with-garmin',
|
||||||
);
|
);
|
||||||
|
|
||||||
expect((component as any).shouldUseSoftSeoFallback({ status: 404 })).toBeFalse();
|
expect(
|
||||||
|
(component as any).shouldUseSoftSeoFallback({ status: 404 }),
|
||||||
|
).toBeFalse();
|
||||||
(component as any).setResponseStatus(404);
|
(component as any).setResponseStatus(404);
|
||||||
(component as any).applyHardErrorSeo();
|
(component as any).applyHardErrorSeo();
|
||||||
|
|
||||||
|
|||||||
@@ -528,9 +528,7 @@ export class ShopPageComponent {
|
|||||||
return this.normalizeRouteParam(this.route.snapshot.paramMap.get(name));
|
return this.normalizeRouteParam(this.route.snapshot.paramMap.get(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
private normalizeRouteParam(
|
private normalizeRouteParam(value: string | null | undefined): string | null {
|
||||||
value: string | null | undefined,
|
|
||||||
): string | null {
|
|
||||||
const normalized = String(value ?? '').trim();
|
const normalized = String(value ?? '').trim();
|
||||||
return normalized || null;
|
return normalized || null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user