diff --git a/src/app/pagenotfound/pagenotfound.component.ts b/src/app/pagenotfound/pagenotfound.component.ts index 97b70b8414..aae2bc9a75 100644 --- a/src/app/pagenotfound/pagenotfound.component.ts +++ b/src/app/pagenotfound/pagenotfound.component.ts @@ -1,12 +1,17 @@ -import { Component } from '@angular/core'; +import { ServerResponseService } from '../shared/server-response.service'; +import { Component, ChangeDetectionStrategy } from '@angular/core'; @Component({ selector: 'ds-pagenotfound', styleUrls: ['./pagenotfound.component.scss'], - templateUrl: './pagenotfound.component.html' + templateUrl: './pagenotfound.component.html', + providers: [ServerResponseService], + changeDetection: ChangeDetectionStrategy.OnPush }) export class PageNotFoundComponent { data: any = {}; - + constructor(responseService: ServerResponseService) { + responseService.setNotFound(); + } } diff --git a/src/app/shared/server-response.service.ts b/src/app/shared/server-response.service.ts new file mode 100644 index 0000000000..f143c56ffb --- /dev/null +++ b/src/app/shared/server-response.service.ts @@ -0,0 +1,26 @@ +import { RESPONSE } from '@nguniversal/express-engine/tokens'; +import { Inject, Injectable, Optional } from '@angular/core'; +import { Response } from 'express'; + +@Injectable() +export class ServerResponseService { + private response: Response; + + constructor(@Optional() @Inject(RESPONSE) response: any) { + this.response = response; + } + + setStatus(code: number, message?: string): this { + if (this.response) { + this.response.statusCode = code; + if (message) { + this.response.statusMessage = message; + } + } + return this; + } + + setNotFound(message = 'Not found'): this { + return this.setStatus(404, message) + } +}