npm run serve:ssr funktioniert und Hamburger Menu bug fix

This commit is contained in:
2026-01-06 22:36:14 +01:00
parent 43027a54f7
commit 4f8fd77f7d
21 changed files with 371 additions and 111 deletions

View File

@@ -1,5 +1,6 @@
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Injectable, PLATFORM_ID, inject } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { lastValueFrom, Observable, of } from 'rxjs';
import { tap } from 'rxjs/operators';
import { CityAndStateResult, CountyResult, GeoResult, IpInfo } from '../../../../bizmatch-server/src/models/main.model';
@@ -21,6 +22,8 @@ export class GeoService {
private readonly storageKey = 'ipInfo';
private readonly boundaryStoragePrefix = 'nominatim_boundary_';
private readonly cacheExpiration = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds
private platformId = inject(PLATFORM_ID);
private isBrowser = isPlatformBrowser(this.platformId);
constructor(private http: HttpClient) {}
@@ -28,6 +31,8 @@ export class GeoService {
* Get cached boundary data from localStorage
*/
private getCachedBoundary(cacheKey: string): any | null {
if (!this.isBrowser) return null;
try {
const cached = localStorage.getItem(this.boundaryStoragePrefix + cacheKey);
if (!cached) {
@@ -54,6 +59,8 @@ export class GeoService {
* Save boundary data to localStorage
*/
private setCachedBoundary(cacheKey: string, data: any): void {
if (!this.isBrowser) return;
try {
const cachedData: CachedBoundary = {
data: data,
@@ -69,6 +76,8 @@ export class GeoService {
* Clear all cached boundary data
*/
clearBoundaryCache(): void {
if (!this.isBrowser) return;
try {
const keys = Object.keys(localStorage);
keys.forEach(key => {
@@ -136,9 +145,11 @@ export class GeoService {
async getIpInfo(): Promise<IpInfo | null> {
// Versuche zuerst, die Daten aus dem sessionStorage zu holen
const storedData = sessionStorage.getItem(this.storageKey);
if (storedData) {
return JSON.parse(storedData);
if (this.isBrowser) {
const storedData = sessionStorage.getItem(this.storageKey);
if (storedData) {
return JSON.parse(storedData);
}
}
try {
@@ -146,7 +157,9 @@ export class GeoService {
const data = await lastValueFrom(this.http.get<IpInfo>(`${this.apiBaseUrl}/bizmatch/geo/ipinfo/georesult/wysiwyg`));
// Speichere die Daten im sessionStorage
sessionStorage.setItem(this.storageKey, JSON.stringify(data));
if (this.isBrowser) {
sessionStorage.setItem(this.storageKey, JSON.stringify(data));
}
return data;
} catch (error) {