mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 13:03:04 +00:00
add prototcol to origin in ServerHardRedirectService
This commit is contained in:
@@ -74,7 +74,7 @@ describe('MetadataService', () => {
|
|||||||
}
|
}
|
||||||
} as any as Router;
|
} as any as Router;
|
||||||
hardRedirectService = jasmine.createSpyObj( {
|
hardRedirectService = jasmine.createSpyObj( {
|
||||||
getRequestOrigin: 'https://request.org',
|
getCurrentOrigin: 'https://request.org',
|
||||||
});
|
});
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@@ -272,7 +272,7 @@ export class MetadataService {
|
|||||||
if (this.currentObject.value instanceof Item) {
|
if (this.currentObject.value instanceof Item) {
|
||||||
let url = this.getMetaTagValue('dc.identifier.uri');
|
let url = this.getMetaTagValue('dc.identifier.uri');
|
||||||
if (hasNoValue(url)) {
|
if (hasNoValue(url)) {
|
||||||
url = new URLCombiner(this.hardRedirectService.getRequestOrigin(), this.router.url).toString();
|
url = new URLCombiner(this.hardRedirectService.getCurrentOrigin(), this.router.url).toString();
|
||||||
}
|
}
|
||||||
this.addMetaTag('citation_abstract_html_url', url);
|
this.addMetaTag('citation_abstract_html_url', url);
|
||||||
}
|
}
|
||||||
@@ -336,7 +336,7 @@ export class MetadataService {
|
|||||||
// Use the found link to set the <meta> tag
|
// Use the found link to set the <meta> tag
|
||||||
this.addMetaTag(
|
this.addMetaTag(
|
||||||
'citation_pdf_url',
|
'citation_pdf_url',
|
||||||
new URLCombiner(this.hardRedirectService.getRequestOrigin(), link).toString()
|
new URLCombiner(this.hardRedirectService.getCurrentOrigin(), link).toString()
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@ import { TestBed } from '@angular/core/testing';
|
|||||||
import { BrowserHardRedirectService } from './browser-hard-redirect.service';
|
import { BrowserHardRedirectService } from './browser-hard-redirect.service';
|
||||||
|
|
||||||
describe('BrowserHardRedirectService', () => {
|
describe('BrowserHardRedirectService', () => {
|
||||||
const origin = 'test origin';
|
const origin = 'https://test-host.com:4000';
|
||||||
const mockLocation = {
|
const mockLocation = {
|
||||||
href: undefined,
|
href: undefined,
|
||||||
pathname: '/pathname',
|
pathname: '/pathname',
|
||||||
@@ -43,7 +43,7 @@ describe('BrowserHardRedirectService', () => {
|
|||||||
describe('when requesting the origin', () => {
|
describe('when requesting the origin', () => {
|
||||||
|
|
||||||
it('should return the location origin', () => {
|
it('should return the location origin', () => {
|
||||||
expect(service.getRequestOrigin()).toEqual(origin);
|
expect(service.getCurrentOrigin()).toEqual(origin);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -28,16 +28,20 @@ export class BrowserHardRedirectService extends HardRedirectService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the origin of a request
|
* Get the current route, with query params included
|
||||||
|
* e.g. /search?page=1&query=open%20access&f.dateIssued.min=1980&f.dateIssued.max=2020
|
||||||
*/
|
*/
|
||||||
getCurrentRoute() {
|
getCurrentRoute(): string {
|
||||||
return this.location.pathname + this.location.search;
|
return this.location.pathname + this.location.search;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the hostname of the request
|
* Get the origin of the current URL
|
||||||
|
* i.e. <scheme> "://" <hostname> [ ":" <port> ]
|
||||||
|
* e.g. if the URL is https://demo7.dspace.org/search?query=test,
|
||||||
|
* the origin would be https://demo7.dspace.org
|
||||||
*/
|
*/
|
||||||
getRequestOrigin() {
|
getCurrentOrigin(): string {
|
||||||
return this.location.origin;
|
return this.location.origin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,10 +18,13 @@ export abstract class HardRedirectService {
|
|||||||
* Get the current route, with query params included
|
* Get the current route, with query params included
|
||||||
* e.g. /search?page=1&query=open%20access&f.dateIssued.min=1980&f.dateIssued.max=2020
|
* e.g. /search?page=1&query=open%20access&f.dateIssued.min=1980&f.dateIssued.max=2020
|
||||||
*/
|
*/
|
||||||
abstract getCurrentRoute();
|
abstract getCurrentRoute(): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the hostname of the request
|
* Get the origin of the current URL
|
||||||
|
* i.e. <scheme> "://" <hostname> [ ":" <port> ]
|
||||||
|
* e.g. if the URL is https://demo7.dspace.org/search?query=test,
|
||||||
|
* the origin would be https://demo7.dspace.org
|
||||||
*/
|
*/
|
||||||
abstract getRequestOrigin();
|
abstract getCurrentOrigin(): string;
|
||||||
}
|
}
|
||||||
|
@@ -7,11 +7,12 @@ describe('ServerHardRedirectService', () => {
|
|||||||
const mockResponse = jasmine.createSpyObj(['redirect', 'end']);
|
const mockResponse = jasmine.createSpyObj(['redirect', 'end']);
|
||||||
|
|
||||||
const service: ServerHardRedirectService = new ServerHardRedirectService(mockRequest, mockResponse);
|
const service: ServerHardRedirectService = new ServerHardRedirectService(mockRequest, mockResponse);
|
||||||
const origin = 'test-host';
|
const origin = 'https://test-host.com:4000';
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
mockRequest.protocol = 'https';
|
||||||
mockRequest.headers = {
|
mockRequest.headers = {
|
||||||
host: 'test-host',
|
host: 'test-host.com:4000',
|
||||||
};
|
};
|
||||||
|
|
||||||
TestBed.configureTestingModule({});
|
TestBed.configureTestingModule({});
|
||||||
@@ -49,7 +50,7 @@ describe('ServerHardRedirectService', () => {
|
|||||||
describe('when requesting the origin', () => {
|
describe('when requesting the origin', () => {
|
||||||
|
|
||||||
it('should return the location origin', () => {
|
it('should return the location origin', () => {
|
||||||
expect(service.getRequestOrigin()).toEqual(origin);
|
expect(service.getCurrentOrigin()).toEqual(origin);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -55,16 +55,19 @@ export class ServerHardRedirectService extends HardRedirectService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the origin of a request
|
* Get the URL of the current route
|
||||||
*/
|
*/
|
||||||
getCurrentRoute() {
|
getCurrentRoute(): string {
|
||||||
return this.req.originalUrl;
|
return this.req.originalUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the hostname of the request
|
* Get the origin of the current URL
|
||||||
|
* i.e. <scheme> "://" <hostname> [ ":" <port> ]
|
||||||
|
* e.g. if the URL is https://demo7.dspace.org/search?query=test,
|
||||||
|
* the origin would be https://demo7.dspace.org
|
||||||
*/
|
*/
|
||||||
getRequestOrigin() {
|
getCurrentOrigin(): string {
|
||||||
return this.req.headers.host;
|
return this.req.protocol + '://' + this.req.headers.host;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user