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
This commit is contained in:
parent
93aa9fdff3
commit
20787395ab
@ -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 }
|
||||
]
|
||||
};
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -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<boolean>(!!localStorage.getItem('token'));
|
||||
|
||||
|
||||
@ -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<AdminStats> {
|
||||
return this.http.get<AdminStats>(`${this.apiUrl}/admin`);
|
||||
|
||||
@ -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<EligibleCommunity[]> {
|
||||
return this.http.get<EligibleCommunity[]>(`${this.apiUrl}/metering-points/${meteringPointId}/eligible-communities`);
|
||||
|
||||
@ -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<MeteringPoint[]> {
|
||||
return this.http.get<MeteringPoint[]>(`${this.apiUrl}/me`);
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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<UserProfile> {
|
||||
return this.http.get<UserProfile>(`${this.apiUrl}/users/me`);
|
||||
|
||||
3
eeg_frontend/src/environments/environment.ts
Normal file
3
eeg_frontend/src/environments/environment.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export const environment = {
|
||||
apiUrl: 'http://localhost:8080'
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user