From 19ca0c086c867328754c8e4e28e930f33d7883f6 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Thu, 13 Nov 2025 21:49:41 +0100 Subject: [PATCH] add base api path to nestjs: "api" --- admin/package.json | 4 ++-- admin/proxy.conf.json | 8 +++++++ admin/src/app/app.config.ts | 8 +++++-- admin/src/app/auth/auth.service.ts | 4 ++-- admin/src/app/components/navbar/navbar.css | 0 admin/src/app/components/navbar/navbar.html | 19 +++++++++++++++ .../src/app/components/navbar/navbar.spec.ts | 23 +++++++++++++++++++ admin/src/app/components/navbar/navbar.ts | 11 +++++++++ server/src/main.ts | 2 ++ 9 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 admin/proxy.conf.json create mode 100644 admin/src/app/components/navbar/navbar.css create mode 100644 admin/src/app/components/navbar/navbar.html create mode 100644 admin/src/app/components/navbar/navbar.spec.ts create mode 100644 admin/src/app/components/navbar/navbar.ts diff --git a/admin/package.json b/admin/package.json index 21b85e5..3f1c974 100644 --- a/admin/package.json +++ b/admin/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "scripts": { "ng": "ng", - "start": "ng serve", + "start": "ng serve --proxy-config proxy.conf.json", "build": "ng build", "watch": "ng build --watch --configuration development", "test": "ng test" @@ -44,4 +44,4 @@ "karma-jasmine-html-reporter": "~2.1.0", "typescript": "~5.9.2" } -} \ No newline at end of file +} diff --git a/admin/proxy.conf.json b/admin/proxy.conf.json new file mode 100644 index 0000000..9ed18d7 --- /dev/null +++ b/admin/proxy.conf.json @@ -0,0 +1,8 @@ +{ + "/api": { + "target": "http://localhost:3000", + "secure": false, + "logLevel": "debug", + "changeOrigin": true + } +} diff --git a/admin/src/app/app.config.ts b/admin/src/app/app.config.ts index 3e5a0b8..10723fe 100644 --- a/admin/src/app/app.config.ts +++ b/admin/src/app/app.config.ts @@ -1,4 +1,7 @@ -import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core'; +import { + ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection, + provideZonelessChangeDetection, +} from '@angular/core'; import { provideRouter } from '@angular/router'; import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; import { HTTP_INTERCEPTORS } from '@angular/common/http'; @@ -9,7 +12,8 @@ import { AuthGuard } from './auth/auth.guard'; export const appConfig: ApplicationConfig = { providers: [ - provideZoneChangeDetection({ eventCoalescing: true }), + provideBrowserGlobalErrorListeners(), + provideZonelessChangeDetection(), provideRouter(routes), provideHttpClient(withInterceptorsFromDi()), AuthService, diff --git a/admin/src/app/auth/auth.service.ts b/admin/src/app/auth/auth.service.ts index 52079da..3b1ee26 100644 --- a/admin/src/app/auth/auth.service.ts +++ b/admin/src/app/auth/auth.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; -import { Observable, of } from 'rxjs'; +import { Observable } from 'rxjs'; import { tap } from 'rxjs/operators'; @Injectable({ @@ -8,7 +8,7 @@ import { tap } from 'rxjs/operators'; }) export class AuthService { private readonly TOKEN_KEY = 'access_token'; - private apiUrl = 'http://localhost:3000/auth'; // Adjust if your server URL is different + private apiUrl = 'http://localhost:4200/api/auth'; // Adjust if your server URL is different constructor(private http: HttpClient) {} diff --git a/admin/src/app/components/navbar/navbar.css b/admin/src/app/components/navbar/navbar.css new file mode 100644 index 0000000..e69de29 diff --git a/admin/src/app/components/navbar/navbar.html b/admin/src/app/components/navbar/navbar.html new file mode 100644 index 0000000..26b93fa --- /dev/null +++ b/admin/src/app/components/navbar/navbar.html @@ -0,0 +1,19 @@ + diff --git a/admin/src/app/components/navbar/navbar.spec.ts b/admin/src/app/components/navbar/navbar.spec.ts new file mode 100644 index 0000000..8893c93 --- /dev/null +++ b/admin/src/app/components/navbar/navbar.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { Navbar } from './navbar'; + +describe('Navbar', () => { + let component: Navbar; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [Navbar] + }) + .compileComponents(); + + fixture = TestBed.createComponent(Navbar); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/admin/src/app/components/navbar/navbar.ts b/admin/src/app/components/navbar/navbar.ts new file mode 100644 index 0000000..016b44d --- /dev/null +++ b/admin/src/app/components/navbar/navbar.ts @@ -0,0 +1,11 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-navbar', + imports: [], + templateUrl: './navbar.html', + styleUrl: './navbar.css', +}) +export class Navbar { + +} diff --git a/server/src/main.ts b/server/src/main.ts index def5b75..b0ac276 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -7,6 +7,8 @@ async function bootstrap() { const app = await NestFactory.create(AppModule); app.useLogger(app.get(DvbookingLoggerService)); + app.setGlobalPrefix('api'); + const config = new DocumentBuilder() .setTitle('DV Booking API') .setDescription('The DV Booking API description')