Skip to content

Commit efd31bd

Browse files
committed
[DSC-1529] Fix errors occurred during SSR
1 parent 4b959a2 commit efd31bd

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/app/core/metadata/metadata.service.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ xdescribe('MetadataService', () => {
123123
appConfig,
124124
authorizationService,
125125
schemaJsonLDService,
126-
'browser'
126+
'browser',
127+
null
127128
);
128129
});
129130

src/app/core/metadata/metadata.service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { getDownloadableBitstream } from '../shared/bitstream.operators';
4242
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';
4343
import { SchemaJsonLDService } from './schema-json-ld/schema-json-ld.service';
4444
import { ITEM } from '../shared/item.resource-type';
45-
import { isPlatformServer } from '@angular/common';
45+
import { DOCUMENT, isPlatformServer } from '@angular/common';
4646
import { Root } from '../data/root.model';
4747
import { environment } from '../../../environments/environment';
4848

@@ -102,6 +102,7 @@ export class MetadataService {
102102
private authorizationService: AuthorizationDataService,
103103
private schemaJsonLDService: SchemaJsonLDService,
104104
@Inject(PLATFORM_ID) private platformId: any,
105+
@Inject(DOCUMENT) private _document: Document,
105106
) {
106107
}
107108

@@ -656,11 +657,11 @@ export class MetadataService {
656657
}
657658

658659
private getMetaTagValue(key: string): string {
659-
return this.currentObject.value.firstMetadataValue(key);
660+
return this.currentObject?.value?.firstMetadataValue(key);
660661
}
661662

662663
private getFirstMetaTagValue(keys: string[]): string {
663-
return this.currentObject.value.firstMetadataValue(keys);
664+
return this.currentObject?.value?.firstMetadataValue(keys);
664665
}
665666

666667
private getMetaTagValuesAndCombine(key: string): string {
@@ -741,7 +742,7 @@ export class MetadataService {
741742

742743

743744
private setGenericPageMetaTags() {
744-
const pageDocumentTitle = document.getElementsByTagName('title')[0].innerText;
745+
const pageDocumentTitle = this._document.getElementsByTagName('title')[0].innerText;
745746
const pageUrl = new URLCombiner(this.hardRedirectService.getCurrentOrigin(), this.router.url).toString();
746747
const genericPageOpenGraphType = 'website';
747748

src/app/core/services/internal-link.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { NativeWindowRef, NativeWindowService } from './window.service';
77
*/
88
@Injectable()
99
export class InternalLinkService {
10-
currentURL = this._window.nativeWindow.location.origin;
10+
currentURL = this._window.nativeWindow?.location?.origin;
1111

1212
constructor(
1313
@Inject(NativeWindowService) protected _window: NativeWindowRef,

0 commit comments

Comments
 (0)