Skip to content

Commit bd98668

Browse files
authored
[ENG-10316] SSR config updates (#889)
- Ticket: [ENG-10316] - Feature flag: n/a ## Summary of Changes 1. Updated config for SSR.
1 parent b86b954 commit bd98668

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/app/core/services/osf-config.service.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff 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
}

src/server.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,25 @@ import {
66
} from '@angular/ssr/node';
77

88
import express from 'express';
9+
import { existsSync, readFileSync } from 'node:fs';
910
import { dirname, resolve } from 'node:path';
1011
import { fileURLToPath } from 'node:url';
1112

1213
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
1314
const 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+
1528
const app = express();
1629
const angularApp = new AngularNodeAppEngine();
1730

0 commit comments

Comments
 (0)