mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 04:53:06 +00:00
Set the HTTP status code to 404 when a page is not found
The browser was getting 200. Fixes https://github.com/DSpace/dspace-angular/issues/91
This commit is contained in:
@@ -1,12 +1,17 @@
|
|||||||
import { Component } from '@angular/core';
|
import { ServerResponseService } from '../shared/server-response.service';
|
||||||
|
import { Component, ChangeDetectionStrategy } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-pagenotfound',
|
selector: 'ds-pagenotfound',
|
||||||
styleUrls: ['./pagenotfound.component.scss'],
|
styleUrls: ['./pagenotfound.component.scss'],
|
||||||
templateUrl: './pagenotfound.component.html'
|
templateUrl: './pagenotfound.component.html',
|
||||||
|
providers: [ServerResponseService],
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush
|
||||||
})
|
})
|
||||||
export class PageNotFoundComponent {
|
export class PageNotFoundComponent {
|
||||||
|
|
||||||
data: any = {};
|
data: any = {};
|
||||||
|
constructor(responseService: ServerResponseService) {
|
||||||
|
responseService.setNotFound();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
26
src/app/shared/server-response.service.ts
Normal file
26
src/app/shared/server-response.service.ts
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user