Skip to content

Commit 2aee6d2

Browse files
[IIIF-188] use * to avoid duplicated config property
1 parent 517adb1 commit 2aee6d2

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

src/app/core/services/server-hard-redirect.service.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('ServerHardRedirectService', () => {
1717

1818
beforeEach(() => {
1919
mockRequest.protocol = 'https';
20+
mockRequest.path = '/bitstreams/test-uuid/download';
2021
mockRequest.headers = {
2122
host: 'test-host.com:4000',
2223
};
@@ -92,4 +93,21 @@ describe('ServerHardRedirectService', () => {
9293
});
9394
});
9495

96+
describe('Should add cors header on download path', () => {
97+
const redirect = 'https://private-url:4000/server/api/bitstreams/uuid';
98+
const environmentWithSSRUrl: any = { ...environment, ...{ ...environment.rest, rest: {
99+
ssrBaseUrl: 'https://private-url:4000/server',
100+
baseUrl: 'https://public-url/server',
101+
} } };
102+
service = new ServerHardRedirectService(environmentWithSSRUrl, mockRequest, mockResponse, serverResponseService);
103+
104+
beforeEach(() => {
105+
service.redirect(redirect);
106+
});
107+
108+
it('should set header', () => {
109+
expect(serverResponseService.setHeader).toHaveBeenCalled();
110+
});
111+
});
112+
95113
});

src/app/core/services/server-hard-redirect.service.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ export class ServerHardRedirectService extends HardRedirectService {
5959
status = 302;
6060
}
6161

62-
console.info(`Redirecting from ${this.req.url} to ${redirectUrl} with ${status}`);
62+
if (this.req.path.endsWith('download')) {
63+
this.setCorsHeader();
64+
}
6365

64-
this.setCorsHeader();
66+
console.info(`Redirecting from ${this.req.url} to ${redirectUrl} with ${status}`);
6567

6668
this.res.redirect(status, redirectUrl);
6769
this.res.end();
@@ -89,15 +91,10 @@ export class ServerHardRedirectService extends HardRedirectService {
8991
}
9092

9193
/**
92-
* Set CORS header to allow embedding of redirected content
94+
* Set CORS header to allow embedding of redirected content.
95+
* The actual security header will be set by the rest
9396
*/
9497
setCorsHeader() {
95-
const currentOrigin = this.getCurrentOrigin();
96-
const allowedOrigins = this.appConfig.rest.allowedOrigins;
97-
98-
if (currentOrigin && allowedOrigins?.length && allowedOrigins.includes(currentOrigin)) {
99-
console.info('Setting cors header for origin ', currentOrigin);
100-
this.responseService.setHeader('Access-Control-Allow-Origin', currentOrigin);
101-
}
98+
this.responseService.setHeader('Access-Control-Allow-Origin', '*');
10299
}
103100
}

0 commit comments

Comments
 (0)