File tree Expand file tree Collapse file tree 2 files changed +24
-7
lines changed
Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -43,20 +43,24 @@ export class OSFConfigService {
4343 * On the server, this is skipped as config is only needed in the browser.
4444 */
4545 async load ( ) : Promise < void > {
46- if ( ! this . config && isPlatformBrowser ( this . platformId ) ) {
46+ if ( this . config ) return ;
47+
48+ if ( isPlatformBrowser ( this . platformId ) ) {
4749 this . config = await lastValueFrom < ConfigModel > (
4850 this . http . get < ConfigModel > ( '/assets/config/config.json' ) . pipe (
4951 shareReplay ( 1 ) ,
5052 catchError ( ( ) => of ( { } as ConfigModel ) )
5153 )
5254 ) ;
55+ } else {
56+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57+ this . config = ( ( globalThis as any ) . __SSR_CONFIG__ ?? { } ) as ConfigModel ;
58+ }
5359
54- // Apply every key from config to environment
55- for ( const [ key , value ] of Object . entries ( this . config ) ) {
56- // eslint-disable-next-line
57- // @ts -ignore
58- this . environment [ key ] = value ;
59- }
60+ for ( const [ key , value ] of Object . entries ( this . config ) ) {
61+ // eslint-disable-next-line
62+ // @ts -ignore
63+ this . environment [ key ] = value ;
6064 }
6165 }
6266}
Original file line number Diff line number Diff line change @@ -6,12 +6,25 @@ import {
66} from '@angular/ssr/node' ;
77
88import express from 'express' ;
9+ import { existsSync , readFileSync } from 'node:fs' ;
910import { dirname , resolve } from 'node:path' ;
1011import { fileURLToPath } from 'node:url' ;
1112
1213const serverDistFolder = dirname ( fileURLToPath ( import . meta. url ) ) ;
1314const browserDistFolder = resolve ( serverDistFolder , '../browser' ) ;
1415
16+ const configPath = resolve ( browserDistFolder , 'assets/config/config.json' ) ;
17+
18+ if ( existsSync ( configPath ) ) {
19+ try {
20+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21+ ( globalThis as any ) . __SSR_CONFIG__ = JSON . parse ( readFileSync ( configPath , 'utf-8' ) ) ;
22+ } catch {
23+ // eslint-disable-next-line no-console
24+ console . warn ( 'Failed to parse SSR config at' , configPath ) ;
25+ }
26+ }
27+
1528const app = express ( ) ;
1629const angularApp = new AngularNodeAppEngine ( ) ;
1730
You can’t perform that action at this time.
0 commit comments