From bf09a151a8411b7efacd90a65447e257a7f52635 Mon Sep 17 00:00:00 2001 From: Dymas Date: Mon, 22 Jun 2026 09:49:50 +0200 Subject: [PATCH] Harden frontend static serving --- src/backend/src/app.module.ts | 21 +++++++++++++++++++-- src/frontend/src/main.ts | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/backend/src/app.module.ts b/src/backend/src/app.module.ts index b55dbd2..c4d789a 100644 --- a/src/backend/src/app.module.ts +++ b/src/backend/src/app.module.ts @@ -16,6 +16,24 @@ import { AuthGuard } from './shared/auth.guard'; import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler'; import { ArchiveModule } from './archive/archive.module'; import { OperationsModule } from './operations/operations.module'; +import * as fs from 'fs'; + +function resolveFrontendRoot(fePath: string | undefined): string { + const configuredRoot = resolve(__dirname, fePath || '../frontend/browser'); + const candidateRoots = [ + configuredRoot, + resolve(configuredRoot, 'browser'), + resolve(configuredRoot, '..'), + ]; + + for (const candidateRoot of candidateRoots) { + if (fs.existsSync(resolve(candidateRoot, 'index.html'))) { + return candidateRoot; + } + } + + return configuredRoot; +} @Module({ imports: [ @@ -38,8 +56,7 @@ import { OperationsModule } from './operations/operations.module'; imports: [ConfigModule], useFactory: async (configService: ConfigService) => [ { - rootPath: resolve( - __dirname, + rootPath: resolveFrontendRoot( configService.get(EnvironmentEnum.FE_PATH), ), exclude: ['/api/(.*)'], diff --git a/src/frontend/src/main.ts b/src/frontend/src/main.ts index 6823534..bfc0286 100644 --- a/src/frontend/src/main.ts +++ b/src/frontend/src/main.ts @@ -1,3 +1,4 @@ +import { isDevMode } from '@angular/core'; import { bootstrapApplication } from '@angular/platform-browser'; import { appConfig } from './app/app.config'; import { AppComponent } from './app/app.component'; @@ -5,4 +6,7 @@ import { devTools } from '@ngneat/elf-devtools'; bootstrapApplication(AppComponent, appConfig) .catch((err) => console.error(err)); -devTools(); + +if (isDevMode()) { + devTools(); +}