Skip to content

Commit f2e9450

Browse files
Andrea Barbassoatarix83
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-1778 (pull request DSpace#1836)
Task/dspace cris 2023 02 x/DSC-1778 Approved-by: Giuseppe Digilio
2 parents 20d3b72 + cbc9ad2 commit f2e9450

4 files changed

Lines changed: 60 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"date-fns": "^2.29.3",
114114
"date-fns-tz": "^1.3.7",
115115
"deepmerge": "^4.3.1",
116+
"domino": "^2.1.6",
116117
"ejs": "^3.1.9",
117118
"express": "^4.18.2",
118119
"express-rate-limit": "^5.1.3",

server.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import * as express from 'express';
2525
import * as ejs from 'ejs';
2626
import * as compression from 'compression';
2727
import * as expressStaticGzip from 'express-static-gzip';
28+
import * as domino from 'domino';
2829
/* eslint-enable import/no-namespace */
2930
import axios from 'axios';
3031
import LRU from 'lru-cache';
@@ -79,6 +80,15 @@ let anonymousCache: LRU<string, any>;
7980
// extend environment with app config for server
8081
extendEnvironmentWithAppConfig(environment, appConfig);
8182

83+
// Create a DOM window object based on the template
84+
const _window = domino.createWindow(indexHtml);
85+
86+
// Assign the DOM window and document objects to the global object
87+
(_window as any).screen = {deviceXDPI: 0, logicalXDPI: 0};
88+
(global as any).window = _window;
89+
(global as any).document = _window.document;
90+
(global as any).navigator = _window.navigator;
91+
8292
// The Express app is exported so that it can be used by serverless Functions.
8393
export function app() {
8494

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { isPlatformBrowser } from '@angular/common';
2+
import {
3+
ChangeDetectorRef,
4+
Directive,
5+
Inject,
6+
OnInit,
7+
PLATFORM_ID,
8+
TemplateRef,
9+
ViewContainerRef,
10+
} from '@angular/core';
11+
12+
@Directive({
13+
selector: '[dsRenderOnlyForBrowser]',
14+
standalone: true,
15+
})
16+
/**
17+
* Structural Directive for rendering a template reference on client side only
18+
*/
19+
export class BrowserOnlyDirective implements OnInit {
20+
21+
constructor(
22+
@Inject(PLATFORM_ID) protected platformId: string,
23+
private viewContainer: ViewContainerRef,
24+
private changeDetector: ChangeDetectorRef,
25+
private templateRef: TemplateRef<any>,
26+
) {
27+
}
28+
29+
ngOnInit(): void {
30+
this.showTemplateBlockInView();
31+
}
32+
33+
/**
34+
* Show template in view container according to platform
35+
*/
36+
private showTemplateBlockInView(): void {
37+
if (!this.templateRef) {
38+
return;
39+
}
40+
this.viewContainer.clear();
41+
42+
if (isPlatformBrowser(this.platformId)) {
43+
this.viewContainer.createEmbeddedView(this.templateRef);
44+
this.changeDetector.markForCheck();
45+
}
46+
}
47+
48+
}

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5305,7 +5305,7 @@ domhandler@^5.0.2, domhandler@^5.0.3:
53055305
dependencies:
53065306
domelementtype "^2.3.0"
53075307

5308-
domino@^2.1.2:
5308+
domino@^2.1.2, domino@^2.1.6:
53095309
version "2.1.6"
53105310
resolved "https://registry.yarnpkg.com/domino/-/domino-2.1.6.tgz#fe4ace4310526e5e7b9d12c7de01b7f485a57ffe"
53115311
integrity sha512-3VdM/SXBZX2omc9JF9nOPCtDaYQ67BGp5CoLpIQlO2KCAPETs8TcDHacF26jXadGbvUteZzRTeos2fhID5+ucQ==

0 commit comments

Comments
 (0)