From 6e55b1ed56fca0813bb47658c88431e4ff712475 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Fri, 29 Mar 2024 23:41:54 +0000 Subject: [PATCH] Make ServeStatic dynamic --- apps/server/src/app.module.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/server/src/app.module.ts b/apps/server/src/app.module.ts index 6c469571..20790972 100644 --- a/apps/server/src/app.module.ts +++ b/apps/server/src/app.module.ts @@ -8,6 +8,20 @@ import { WsModule } from './ws/ws.module'; import { ServeStaticModule } from '@nestjs/serve-static'; import { join } from 'path'; import { KyselyDbModule } from './kysely/kysely-db.module'; +import * as fs from 'fs'; + +const clientDistPath = join(__dirname, '..', '..', 'client/dist'); + +function getServeStaticModule() { + if (fs.existsSync(clientDistPath)) { + return [ + ServeStaticModule.forRoot({ + rootPath: clientDistPath, + }), + ]; + } + return []; +} @Module({ imports: [ @@ -16,9 +30,7 @@ import { KyselyDbModule } from './kysely/kysely-db.module'; EnvironmentModule, CollaborationModule, WsModule, - ServeStaticModule.forRoot({ - rootPath: join(__dirname, '..', '..', '..', 'client/dist'), - }), + ...getServeStaticModule(), ], controllers: [AppController], providers: [AppService],