Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/frontend/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import {
provideClientHydration,
withEventReplay,
} from '@angular/platform-browser';
import { BASE_API_URL, getBaseApiUrl } from './shared/context/base-api-url';

export const appConfig: ApplicationConfig = {
providers: [
provideClientHydration(withEventReplay()),
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(appRoutes),
provideHttpClient(withFetch()),
{
provide: BASE_API_URL,
useFactory: getBaseApiUrl,
},
],
};
13 changes: 13 additions & 0 deletions apps/frontend/src/app/shared/context/base-api-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { InjectionToken, isDevMode } from '@angular/core';

export const BASE_API_URL = new InjectionToken<string>('BASE_API_URL');

export function getBaseApiUrl(): string {
const isDevelopment =
window.location.hostname === 'localhost' ||
!window.location.protocol.startsWith('https');

return isDevelopment || isDevMode()
? 'http://localhost:3001'
: 'https://api.devswhorun.dev';
}
4 changes: 3 additions & 1 deletion apps/frontend/src/app/shared/services/auth-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { tap, catchError } from 'rxjs/operators';
import { UserProfile, AuthResponse } from '../types';
import { BASE_API_URL } from '../context/base-api-url';

@Injectable({
providedIn: 'root',
})
export class AuthApiService {
private http = inject(HttpClient);
private baseUrl = inject(BASE_API_URL);

private readonly apiUrl = 'http://localhost:3001/auth';
private readonly apiUrl = `${this.baseUrl}/auth`;

public currentUser = signal<UserProfile | null>(null);

Expand Down
4 changes: 3 additions & 1 deletion apps/frontend/src/app/shared/services/event-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Event } from '../types';
import { BASE_API_URL } from '../context/base-api-url';

@Injectable({
providedIn: 'root',
})
export class EventApiService {
private http = inject(HttpClient);
private baseUrl = inject(BASE_API_URL);

private readonly apiUrl = 'http://localhost:3001/events';
private readonly apiUrl = `${this.baseUrl}/events`;

getEvents(): Observable<Event[]> {
return this.http.get<Event[]>(`${this.apiUrl}/all`);
Expand Down
Loading