From 20787395aba2d7b8d55c202d4e4477dda574007f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20M=C3=BCller?= Date: Wed, 22 Jul 2026 07:50:38 +0200 Subject: [PATCH] refactor(frontend): replace hardcoded localhost URLs with environment config - Create environment.ts with apiUrl constant - Update all 6 services to use environment.apiUrl - Update forgot-password and reset-password pages - Update app.config.ts BASE_PATH provider --- eeg_frontend/src/app/app.config.ts | 3 ++- .../src/app/pages/forgot-password/forgot-password.ts | 3 ++- eeg_frontend/src/app/pages/reset-password/reset-password.ts | 3 ++- eeg_frontend/src/app/services/auth.ts | 5 ++--- eeg_frontend/src/app/services/dashboard.ts | 3 ++- eeg_frontend/src/app/services/membership.ts | 3 ++- eeg_frontend/src/app/services/metering-point.ts | 3 ++- eeg_frontend/src/app/services/notification.ts | 3 ++- eeg_frontend/src/app/services/user.ts | 3 ++- eeg_frontend/src/environments/environment.ts | 3 +++ 10 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 eeg_frontend/src/environments/environment.ts diff --git a/eeg_frontend/src/app/app.config.ts b/eeg_frontend/src/app/app.config.ts index 623aad2..3d9c586 100644 --- a/eeg_frontend/src/app/app.config.ts +++ b/eeg_frontend/src/app/app.config.ts @@ -5,6 +5,7 @@ import {provideHttpClient, withFetch, withInterceptors} from '@angular/common/ht import {BASE_PATH} from './api'; import {jwtInterceptor} from './interceptors/jwt.interceptor'; import {errorInterceptor} from './interceptors/error.interceptor'; +import {environment} from '../environments/environment'; export const appConfig: ApplicationConfig = { providers: [ @@ -12,6 +13,6 @@ export const appConfig: ApplicationConfig = { provideRouter(routes), provideHttpClient(withFetch(), withInterceptors([jwtInterceptor, errorInterceptor])), - { provide: BASE_PATH, useValue: 'http://localhost:8080' } + { provide: BASE_PATH, useValue: environment.apiUrl } ] }; diff --git a/eeg_frontend/src/app/pages/forgot-password/forgot-password.ts b/eeg_frontend/src/app/pages/forgot-password/forgot-password.ts index 7eafedb..d3fa7d0 100644 --- a/eeg_frontend/src/app/pages/forgot-password/forgot-password.ts +++ b/eeg_frontend/src/app/pages/forgot-password/forgot-password.ts @@ -3,6 +3,7 @@ import {ReactiveFormsModule, FormBuilder, FormGroup, Validators} from '@angular/ import {Router, RouterLink} from '@angular/router'; import {HttpClient} from '@angular/common/http'; import {ToastService} from '../../services/toast'; +import {environment} from '../../../environments/environment'; @Component({ selector: 'app-forgot-password', @@ -71,7 +72,7 @@ export class ForgotPasswordComponent { this.isLoading.set(true); - this.http.post('http://localhost:8080/api/auth/forgot-password', this.form.value).subscribe({ + this.http.post(`${environment.apiUrl}/api/auth/forgot-password`, this.form.value).subscribe({ next: () => { this.isLoading.set(false); this.isSuccess.set(true); diff --git a/eeg_frontend/src/app/pages/reset-password/reset-password.ts b/eeg_frontend/src/app/pages/reset-password/reset-password.ts index bfce196..2f4e040 100644 --- a/eeg_frontend/src/app/pages/reset-password/reset-password.ts +++ b/eeg_frontend/src/app/pages/reset-password/reset-password.ts @@ -3,6 +3,7 @@ import {ReactiveFormsModule, FormBuilder, FormGroup, Validators} from '@angular/ import {ActivatedRoute, Router, RouterLink} from '@angular/router'; import {HttpClient} from '@angular/common/http'; import {ToastService} from '../../services/toast'; +import {environment} from '../../../environments/environment'; @Component({ selector: 'app-reset-password', @@ -95,7 +96,7 @@ export class ResetPasswordComponent implements OnInit { this.isLoading.set(true); - this.http.post('http://localhost:8080/api/auth/reset-password', { + this.http.post(`${environment.apiUrl}/api/auth/reset-password`, { token: this.token, newPassword: this.form.value.newPassword }).subscribe({ diff --git a/eeg_frontend/src/app/services/auth.ts b/eeg_frontend/src/app/services/auth.ts index 1e60b55..ab8965d 100644 --- a/eeg_frontend/src/app/services/auth.ts +++ b/eeg_frontend/src/app/services/auth.ts @@ -2,15 +2,14 @@ import {inject, Injectable, signal} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {BehaviorSubject, Observable, tap} from 'rxjs'; import {AuthResponse} from '../api'; +import {environment} from '../../environments/environment'; @Injectable({ providedIn: 'root' }) export class AuthService { private http = inject(HttpClient); - - // Die URL zu deinem lokalen Spring Boot Backend - private apiUrl = 'http://localhost:8080/api/auth'; + private apiUrl = `${environment.apiUrl}/api/auth`; private isLoggedInSubject = new BehaviorSubject(!!localStorage.getItem('token')); diff --git a/eeg_frontend/src/app/services/dashboard.ts b/eeg_frontend/src/app/services/dashboard.ts index e6506a1..80c0974 100644 --- a/eeg_frontend/src/app/services/dashboard.ts +++ b/eeg_frontend/src/app/services/dashboard.ts @@ -1,6 +1,7 @@ import {inject, Injectable} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {Observable} from 'rxjs'; +import {environment} from '../../environments/environment'; export interface AdminStats { totalCommunities: number; @@ -17,7 +18,7 @@ export interface UserStats { @Injectable({providedIn: 'root'}) export class DashboardService { private http = inject(HttpClient); - private apiUrl = 'http://localhost:8080/api/dashboard'; + private apiUrl = `${environment.apiUrl}/api/dashboard`; getAdminStats(): Observable { return this.http.get(`${this.apiUrl}/admin`); diff --git a/eeg_frontend/src/app/services/membership.ts b/eeg_frontend/src/app/services/membership.ts index d8bb472..a907293 100644 --- a/eeg_frontend/src/app/services/membership.ts +++ b/eeg_frontend/src/app/services/membership.ts @@ -1,6 +1,7 @@ import {inject, Injectable} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {Observable} from 'rxjs'; +import {environment} from '../../environments/environment'; export interface EligibleCommunity { id: string; @@ -41,7 +42,7 @@ export interface PendingMembershipResponse { @Injectable({providedIn: 'root'}) export class MembershipService { private http = inject(HttpClient); - private apiUrl = 'http://localhost:8080/api/community'; + private apiUrl = `${environment.apiUrl}/api/community`; getEligibleCommunities(meteringPointId: string): Observable { return this.http.get(`${this.apiUrl}/metering-points/${meteringPointId}/eligible-communities`); diff --git a/eeg_frontend/src/app/services/metering-point.ts b/eeg_frontend/src/app/services/metering-point.ts index 7baa874..df7df11 100644 --- a/eeg_frontend/src/app/services/metering-point.ts +++ b/eeg_frontend/src/app/services/metering-point.ts @@ -1,6 +1,7 @@ import {inject, Injectable} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {Observable} from 'rxjs'; +import {environment} from '../../environments/environment'; export type PointType = 'CONSUMER' | 'PRODUCER' | 'PROSUME'; export type MakoState = 'NEW' | 'WAITING_FOR_CONSENT' | 'CONSENT_GRANTED' | 'ACTIVE' | 'REJECTED' | 'ERROR'; @@ -27,7 +28,7 @@ export interface UpdateMeteringPointRequest { @Injectable({providedIn: 'root'}) export class MeteringPointService { private http = inject(HttpClient); - private apiUrl = 'http://localhost:8080/api/community/metering-points'; + private apiUrl = `${environment.apiUrl}/api/community/metering-points`; getMyMeteringPoints(): Observable { return this.http.get(`${this.apiUrl}/me`); diff --git a/eeg_frontend/src/app/services/notification.ts b/eeg_frontend/src/app/services/notification.ts index 27ff5a8..addb09b 100644 --- a/eeg_frontend/src/app/services/notification.ts +++ b/eeg_frontend/src/app/services/notification.ts @@ -2,6 +2,7 @@ import {inject, Injectable, signal} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {Observable} from 'rxjs'; import {tap} from 'rxjs/operators'; +import {environment} from '../../environments/environment'; export interface Notification { id: string; @@ -16,7 +17,7 @@ export interface Notification { @Injectable({providedIn: 'root'}) export class NotificationService { private http = inject(HttpClient); - private apiUrl = 'http://localhost:8080/api/notifications'; + private apiUrl = `${environment.apiUrl}/api/notifications`; unreadCount = signal(0); diff --git a/eeg_frontend/src/app/services/user.ts b/eeg_frontend/src/app/services/user.ts index f3f145b..4e83fbe 100644 --- a/eeg_frontend/src/app/services/user.ts +++ b/eeg_frontend/src/app/services/user.ts @@ -1,6 +1,7 @@ import {inject, Injectable} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {Observable} from 'rxjs'; +import {environment} from '../../environments/environment'; export interface UserProfile { id: string; @@ -31,7 +32,7 @@ export interface ChangeEmailRequest { @Injectable({providedIn: 'root'}) export class UserService { private http = inject(HttpClient); - private apiUrl = 'http://localhost:8080/api'; + private apiUrl = `${environment.apiUrl}/api`; getProfile(): Observable { return this.http.get(`${this.apiUrl}/users/me`); diff --git a/eeg_frontend/src/environments/environment.ts b/eeg_frontend/src/environments/environment.ts new file mode 100644 index 0000000..1887f47 --- /dev/null +++ b/eeg_frontend/src/environments/environment.ts @@ -0,0 +1,3 @@ +export const environment = { + apiUrl: 'http://localhost:8080' +};