1- import { join } from 'node:path' ;
1+ import { join , resolve } from 'node:path' ;
2+ import { fileURLToPath } from 'node:url' ;
23
34import {
45 DynamicModule ,
56 ForwardReference ,
67 Logger ,
8+ MiddlewareConsumer ,
79 Module ,
10+ NestModule ,
811} from '@nestjs/common' ;
912import { ScheduleModule } from '@nestjs/schedule' ;
1013import { ServeStaticModule } from '@nestjs/serve-static' ;
@@ -16,7 +19,7 @@ import { ADD_ENABLED_FEATURES, ServerConfigModule } from './core/config';
1619import { DocModule } from './core/doc' ;
1720import { FeatureModule } from './core/features' ;
1821import { QuotaModule } from './core/quota' ;
19- import { CustomSetupModule } from './core/setup' ;
22+ import { CustomSetupModule , SetupMiddleware } from './core/setup' ;
2023import { StorageModule } from './core/storage' ;
2124import { SyncModule } from './core/sync' ;
2225import { UserModule } from './core/user' ;
@@ -135,16 +138,26 @@ export class AppModuleBuilder {
135138 }
136139
137140 compile ( ) {
141+ const configure = ( consumer : MiddlewareConsumer ) => {
142+ if ( this . config . isSelfhosted ) {
143+ consumer . apply ( SetupMiddleware ) . forRoutes ( '*' ) ;
144+ }
145+ } ;
146+
138147 @Module ( {
139148 imports : this . modules ,
140149 controllers : this . config . isSelfhosted ? [ ] : [ AppController ] ,
141150 } )
142- class AppModule { }
151+ class AppModule implements NestModule {
152+ configure = configure ;
153+ }
143154
144155 return AppModule ;
145156 }
146157}
147158
159+ const pwd = resolve ( fileURLToPath ( import . meta. url ) , '../../' ) ;
160+
148161function buildAppModule ( ) {
149162 AFFiNE = mergeConfigOverride ( AFFiNE ) ;
150163 const factor = new AppModuleBuilder ( AFFiNE ) ;
@@ -179,12 +192,12 @@ function buildAppModule() {
179192 config => config . isSelfhosted ,
180193 CustomSetupModule ,
181194 ServeStaticModule . forRoot ( {
182- rootPath : join ( '/app ', 'static ' ) ,
183- exclude : [ '/ admin*' ] ,
195+ rootPath : join ( pwd , 'static ', 'admin ' ) ,
196+ renderPath : / ^ \/ a d m i n \/ ? / ,
184197 } ) ,
185198 ServeStaticModule . forRoot ( {
186- rootPath : join ( '/app' , 'static' , 'admin ') ,
187- serveRoot : '/admin ' ,
199+ rootPath : join ( pwd , 'static' ) ,
200+ renderPath : '* ' ,
188201 } )
189202 ) ;
190203
0 commit comments