Skip to content

Commit

Permalink
feat(@nguniversal/common): add ng-server-context for SSR pages
Browse files Browse the repository at this point in the history
This provides an easy way to distinguish between SSR, SSG, and client-side apps (CSR).

Closes #2612
  • Loading branch information
alan-agius4 committed Oct 12, 2022
1 parent affd573 commit a62d3d3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modules/common/engine/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import type { StaticProvider, Type } from '@angular/core';
import { INITIAL_CONFIG, renderModule } from '@angular/platform-server';
import { INITIAL_CONFIG, renderModule, ɵSERVER_CONTEXT } from '@angular/platform-server';
import { ɵInlineCriticalCssProcessor as InlineCriticalCssProcessor } from '@nguniversal/common/tools';
import * as fs from 'fs';
import { dirname, resolve } from 'path';
Expand Down Expand Up @@ -77,7 +77,11 @@ export class CommonEngine {
}

// if opts.document dosen't exist then opts.documentFilePath must
const extraProviders = [...(opts.providers || []), ...(this.providers || [])];
const extraProviders: StaticProvider[] = [
{ provide: ɵSERVER_CONTEXT, useValue: 'ssr' },
...(opts.providers ?? []),
...this.providers,
];

let doc = opts.document;
if (!doc && opts.documentFilePath) {
Expand Down

0 comments on commit a62d3d3

Please sign in to comment.