Harden frontend static serving
This commit is contained in:
@@ -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/(.*)'],
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user