Skip to content

Instantly share code, notes, and snippets.

@ssatz
Last active October 16, 2018 12:17
Show Gist options
  • Save ssatz/0081f75608fe6c8e5e23cd0ee88fbd3e to your computer and use it in GitHub Desktop.
Save ssatz/0081f75608fe6c8e5e23cd0ee88fbd3e to your computer and use it in GitHub Desktop.
Angular Server Response
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);
}
}
}
@ssatz
Copy link
Author

ssatz commented Oct 16, 2018

inject ServerReponseService in not found and call the method setStatus with 404 and error message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment