Last active
October 16, 2018 12:17
-
-
Save ssatz/0081f75608fe6c8e5e23cd0ee88fbd3e to your computer and use it in GitHub Desktop.
Angular Server Response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { RESPONSE } from '@nguniversal/express-engine/tokens'; | |
import { Inject, Injectable, Optional } from '@angular/core'; | |
@Injectable() | |
export class ServerReponseService { | |
constructor(@Optional() @Inject(RESPONSE) private _response: any) { | |
} | |
public setStatus(code: number, message: string): void { | |
if (this._response) { | |
this.setCacheNone(); | |
this._response.statusCode = code; | |
this._response.statusMessage = message; | |
} | |
} | |
setCacheNone():void{ | |
if (this._response) { | |
this.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); | |
this.setHeader('Pragma', 'no-cache'); | |
} | |
} | |
setHeader(key: string, value: string): void { | |
if (this._response) { | |
this._response.header(key, value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
inject ServerReponseService in not found and call the method setStatus with 404 and error message