Harden frontend static serving

This commit is contained in:
Dymas
2026-06-22 09:49:50 +02:00
parent f467836046
commit bf09a151a8
2 changed files with 24 additions and 3 deletions
+19 -2
View File
@@ -16,6 +16,24 @@ import { AuthGuard } from './shared/auth.guard';
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler'; import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';
import { ArchiveModule } from './archive/archive.module'; import { ArchiveModule } from './archive/archive.module';
import { OperationsModule } from './operations/operations.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({ @Module({
imports: [ imports: [
@@ -38,8 +56,7 @@ import { OperationsModule } from './operations/operations.module';
imports: [ConfigModule], imports: [ConfigModule],
useFactory: async (configService: ConfigService) => [ useFactory: async (configService: ConfigService) => [
{ {
rootPath: resolve( rootPath: resolveFrontendRoot(
__dirname,
configService.get<string>(EnvironmentEnum.FE_PATH), configService.get<string>(EnvironmentEnum.FE_PATH),
), ),
exclude: ['/api/(.*)'], exclude: ['/api/(.*)'],
+4
View File
@@ -1,3 +1,4 @@
import { isDevMode } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser'; import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config'; import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component'; import { AppComponent } from './app/app.component';
@@ -5,4 +6,7 @@ import { devTools } from '@ngneat/elf-devtools';
bootstrapApplication(AppComponent, appConfig) bootstrapApplication(AppComponent, appConfig)
.catch((err) => console.error(err)); .catch((err) => console.error(err));
if (isDevMode()) {
devTools(); devTools();
}