Skip to content

Commit 9a58f96

Browse files
[IIIF-188] use * to avoid duplicated config property
1 parent 3bd1d2d commit 9a58f96

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
@@ -72,9 +72,11 @@ export class ServerHardRedirectService extends HardRedirectService {
7272
status = 302;
7373
}
7474

75-
console.info(`Redirecting from ${this.req.url} to ${redirectUrl} with ${status}`);
75+
if (this.req.path.endsWith('download')) {
76+
this.setCorsHeader();
77+
}
7678

77-
this.setCorsHeader();
79+
console.info(`Redirecting from ${this.req.url} to ${redirectUrl} with ${status}`);
7880

7981
this.res.redirect(status, redirectUrl);
8082
this.res.end();
@@ -102,15 +104,10 @@ export class ServerHardRedirectService extends HardRedirectService {
102104
}
103105

104106
/**
105-
* Set CORS header to allow embedding of redirected content
107+
* Set CORS header to allow embedding of redirected content.
108+
* The actual security header will be set by the rest
106109
*/
107110
setCorsHeader() {
108-
const currentOrigin = this.getCurrentOrigin();
109-
const allowedOrigins = this.appConfig.rest.allowedOrigins;
110-
111-
if (currentOrigin && allowedOrigins?.length && allowedOrigins.includes(currentOrigin)) {
112-
console.info('Setting cors header for origin ', currentOrigin);
113-
this.responseService.setHeader('Access-Control-Allow-Origin', currentOrigin);
114-
}
111+
this.responseService.setHeader('Access-Control-Allow-Origin', '*');
115112
}
116113
}

0 commit comments

Comments
 (0)