diff --git a/scripts/set-env.ts b/scripts/set-env.ts index 5eee22a4be..5570b77218 100644 --- a/scripts/set-env.ts +++ b/scripts/set-env.ts @@ -54,6 +54,13 @@ import(environmentFilePath) function generateEnvironmentFile(file: GlobalConfig): void { file.production = production; buildBaseUrls(file); + + // TODO remove workaround in beta 5 + if (file.rest.nameSpace.match("(.*)/api/?$") !== null) { + const newValue = getNameSpace(file.rest.nameSpace); + console.log(colors.white.bgMagenta.bold(`The rest.nameSpace property in your environment file or in your DSPACE_REST_NAMESPACE environment variable ends with '/api'.\nThis is deprecated. As '/api' isn't configurable on the rest side, it shouldn't be repeated in every environment file.\nPlease change the rest nameSpace to '${newValue}'`)); + } + const contents = `export const environment = ` + JSON.stringify(file); writeFile(targetPath, contents, (err) => { if (err) { @@ -112,5 +119,16 @@ function getPort(port: number): string { } function getNameSpace(nameSpace: string): string { - return nameSpace ? nameSpace.charAt(0) === '/' ? nameSpace : '/' + nameSpace : ''; + // TODO remove workaround in beta 5 + const apiMatches = nameSpace.match("(.*)/api/?$"); + if (apiMatches != null) { + let newValue = '/' + if (hasValue(apiMatches[1])) { + newValue = apiMatches[1]; + } + return newValue; + } + else { + return nameSpace ? nameSpace.charAt(0) === '/' ? nameSpace : '/' + nameSpace : ''; + } } diff --git a/src/app/core/shared/hal-endpoint.service.spec.ts b/src/app/core/shared/hal-endpoint.service.spec.ts index 5f5c31f29d..31538e6be4 100644 --- a/src/app/core/shared/hal-endpoint.service.spec.ts +++ b/src/app/core/shared/hal-endpoint.service.spec.ts @@ -61,7 +61,7 @@ describe('HALEndpointService', () => { describe('getRootEndpointMap', () => { it('should configure a new EndpointMapRequest', () => { (service as any).getRootEndpointMap(); - const expected = new EndpointMapRequest(requestService.generateRequestId(), environment.rest.baseUrl); + const expected = new EndpointMapRequest(requestService.generateRequestId(), environment.rest.baseUrl + '/api'); expect(requestService.configure).toHaveBeenCalledWith(expected); }); diff --git a/src/app/core/shared/hal-endpoint.service.ts b/src/app/core/shared/hal-endpoint.service.ts index d8b1d8931f..a74650ce5a 100644 --- a/src/app/core/shared/hal-endpoint.service.ts +++ b/src/app/core/shared/hal-endpoint.service.ts @@ -16,7 +16,7 @@ export class HALEndpointService { } protected getRootHref(): string { - return new RESTURLCombiner('/').toString(); + return new RESTURLCombiner('/api').toString(); } protected getRootEndpointMap(): Observable {