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 {BASE_PATH} from './api';
|
||||||
import {jwtInterceptor} from './interceptors/jwt.interceptor';
|
import {jwtInterceptor} from './interceptors/jwt.interceptor';
|
||||||
import {errorInterceptor} from './interceptors/error.interceptor';
|
import {errorInterceptor} from './interceptors/error.interceptor';
|
||||||
|
import {environment} from '../environments/environment';
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [
|
providers: [
|
||||||
@ -12,6 +13,6 @@ export const appConfig: ApplicationConfig = {
|
|||||||
provideRouter(routes),
|
provideRouter(routes),
|
||||||
provideHttpClient(withFetch(),
|
provideHttpClient(withFetch(),
|
||||||
withInterceptors([jwtInterceptor, errorInterceptor])),
|
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 {Router, RouterLink} from '@angular/router';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {ToastService} from '../../services/toast';
|
import {ToastService} from '../../services/toast';
|
||||||
|
import {environment} from '../../../environments/environment';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-forgot-password',
|
selector: 'app-forgot-password',
|
||||||
@ -71,7 +72,7 @@ export class ForgotPasswordComponent {
|
|||||||
|
|
||||||
this.isLoading.set(true);
|
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: () => {
|
next: () => {
|
||||||
this.isLoading.set(false);
|
this.isLoading.set(false);
|
||||||
this.isSuccess.set(true);
|
this.isSuccess.set(true);
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import {ReactiveFormsModule, FormBuilder, FormGroup, Validators} from '@angular/
|
|||||||
import {ActivatedRoute, Router, RouterLink} from '@angular/router';
|
import {ActivatedRoute, Router, RouterLink} from '@angular/router';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {ToastService} from '../../services/toast';
|
import {ToastService} from '../../services/toast';
|
||||||
|
import {environment} from '../../../environments/environment';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-reset-password',
|
selector: 'app-reset-password',
|
||||||
@ -95,7 +96,7 @@ export class ResetPasswordComponent implements OnInit {
|
|||||||
|
|
||||||
this.isLoading.set(true);
|
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,
|
token: this.token,
|
||||||
newPassword: this.form.value.newPassword
|
newPassword: this.form.value.newPassword
|
||||||
}).subscribe({
|
}).subscribe({
|
||||||
|
|||||||
@ -2,15 +2,14 @@ import {inject, Injectable, signal} from '@angular/core';
|
|||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {BehaviorSubject, Observable, tap} from 'rxjs';
|
import {BehaviorSubject, Observable, tap} from 'rxjs';
|
||||||
import {AuthResponse} from '../api';
|
import {AuthResponse} from '../api';
|
||||||
|
import {environment} from '../../environments/environment';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class AuthService {
|
export class AuthService {
|
||||||
private http = inject(HttpClient);
|
private http = inject(HttpClient);
|
||||||
|
private apiUrl = `${environment.apiUrl}/api/auth`;
|
||||||
// Die URL zu deinem lokalen Spring Boot Backend
|
|
||||||
private apiUrl = 'http://localhost:8080/api/auth';
|
|
||||||
|
|
||||||
private isLoggedInSubject = new BehaviorSubject<boolean>(!!localStorage.getItem('token'));
|
private isLoggedInSubject = new BehaviorSubject<boolean>(!!localStorage.getItem('token'));
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import {inject, Injectable} from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
|
import {environment} from '../../environments/environment';
|
||||||
|
|
||||||
export interface AdminStats {
|
export interface AdminStats {
|
||||||
totalCommunities: number;
|
totalCommunities: number;
|
||||||
@ -17,7 +18,7 @@ export interface UserStats {
|
|||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
export class DashboardService {
|
export class DashboardService {
|
||||||
private http = inject(HttpClient);
|
private http = inject(HttpClient);
|
||||||
private apiUrl = 'http://localhost:8080/api/dashboard';
|
private apiUrl = `${environment.apiUrl}/api/dashboard`;
|
||||||
|
|
||||||
getAdminStats(): Observable<AdminStats> {
|
getAdminStats(): Observable<AdminStats> {
|
||||||
return this.http.get<AdminStats>(`${this.apiUrl}/admin`);
|
return this.http.get<AdminStats>(`${this.apiUrl}/admin`);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import {inject, Injectable} from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
|
import {environment} from '../../environments/environment';
|
||||||
|
|
||||||
export interface EligibleCommunity {
|
export interface EligibleCommunity {
|
||||||
id: string;
|
id: string;
|
||||||
@ -41,7 +42,7 @@ export interface PendingMembershipResponse {
|
|||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
export class MembershipService {
|
export class MembershipService {
|
||||||
private http = inject(HttpClient);
|
private http = inject(HttpClient);
|
||||||
private apiUrl = 'http://localhost:8080/api/community';
|
private apiUrl = `${environment.apiUrl}/api/community`;
|
||||||
|
|
||||||
getEligibleCommunities(meteringPointId: string): Observable<EligibleCommunity[]> {
|
getEligibleCommunities(meteringPointId: string): Observable<EligibleCommunity[]> {
|
||||||
return this.http.get<EligibleCommunity[]>(`${this.apiUrl}/metering-points/${meteringPointId}/eligible-communities`);
|
return this.http.get<EligibleCommunity[]>(`${this.apiUrl}/metering-points/${meteringPointId}/eligible-communities`);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import {inject, Injectable} from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
|
import {environment} from '../../environments/environment';
|
||||||
|
|
||||||
export type PointType = 'CONSUMER' | 'PRODUCER' | 'PROSUME';
|
export type PointType = 'CONSUMER' | 'PRODUCER' | 'PROSUME';
|
||||||
export type MakoState = 'NEW' | 'WAITING_FOR_CONSENT' | 'CONSENT_GRANTED' | 'ACTIVE' | 'REJECTED' | 'ERROR';
|
export type MakoState = 'NEW' | 'WAITING_FOR_CONSENT' | 'CONSENT_GRANTED' | 'ACTIVE' | 'REJECTED' | 'ERROR';
|
||||||
@ -27,7 +28,7 @@ export interface UpdateMeteringPointRequest {
|
|||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
export class MeteringPointService {
|
export class MeteringPointService {
|
||||||
private http = inject(HttpClient);
|
private http = inject(HttpClient);
|
||||||
private apiUrl = 'http://localhost:8080/api/community/metering-points';
|
private apiUrl = `${environment.apiUrl}/api/community/metering-points`;
|
||||||
|
|
||||||
getMyMeteringPoints(): Observable<MeteringPoint[]> {
|
getMyMeteringPoints(): Observable<MeteringPoint[]> {
|
||||||
return this.http.get<MeteringPoint[]>(`${this.apiUrl}/me`);
|
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 {HttpClient} from '@angular/common/http';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {tap} from 'rxjs/operators';
|
import {tap} from 'rxjs/operators';
|
||||||
|
import {environment} from '../../environments/environment';
|
||||||
|
|
||||||
export interface Notification {
|
export interface Notification {
|
||||||
id: string;
|
id: string;
|
||||||
@ -16,7 +17,7 @@ export interface Notification {
|
|||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
export class NotificationService {
|
export class NotificationService {
|
||||||
private http = inject(HttpClient);
|
private http = inject(HttpClient);
|
||||||
private apiUrl = 'http://localhost:8080/api/notifications';
|
private apiUrl = `${environment.apiUrl}/api/notifications`;
|
||||||
|
|
||||||
unreadCount = signal(0);
|
unreadCount = signal(0);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import {inject, Injectable} from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
|
import {environment} from '../../environments/environment';
|
||||||
|
|
||||||
export interface UserProfile {
|
export interface UserProfile {
|
||||||
id: string;
|
id: string;
|
||||||
@ -31,7 +32,7 @@ export interface ChangeEmailRequest {
|
|||||||
@Injectable({providedIn: 'root'})
|
@Injectable({providedIn: 'root'})
|
||||||
export class UserService {
|
export class UserService {
|
||||||
private http = inject(HttpClient);
|
private http = inject(HttpClient);
|
||||||
private apiUrl = 'http://localhost:8080/api';
|
private apiUrl = `${environment.apiUrl}/api`;
|
||||||
|
|
||||||
getProfile(): Observable<UserProfile> {
|
getProfile(): Observable<UserProfile> {
|
||||||
return this.http.get<UserProfile>(`${this.apiUrl}/users/me`);
|
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