From df9c1fb99e57075b9e8d43114440b1889bb06821 Mon Sep 17 00:00:00 2001 From: minux Date: Tue, 20 Aug 2024 19:37:05 +0900 Subject: [PATCH] Fix directory link (#1019) --- .../linecorp/centraldogma/server/CentralDogma.java | 3 ++- webapp/src/dogma/features/file/FileList.tsx | 2 +- webapp/tests/dogma/feature/file/FileList.test.tsx | 12 ++++++------ .../xds/group/v1/XdsGroupServiceTest.java | 11 ++++++++++- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/com/linecorp/centraldogma/server/CentralDogma.java b/server/src/main/java/com/linecorp/centraldogma/server/CentralDogma.java index a7d8af4af8..e39ba0f290 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/CentralDogma.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/CentralDogma.java @@ -888,7 +888,8 @@ protected HttpResponse doGet(ServiceRequestContext ctx, HttpRequest req) { // Serve all web resources except for '/app'. sb.route() .pathPrefix("/") - .exclude("/app") + .exclude("prefix:/app") + .exclude("prefix:/api") .build(FileService.builder(CentralDogma.class.getClassLoader(), "com/linecorp/centraldogma/webapp") .cacheControl(ServerCacheControl.REVALIDATED) diff --git a/webapp/src/dogma/features/file/FileList.tsx b/webapp/src/dogma/features/file/FileList.tsx index 8809dfdd7f..ecfeb2e9d6 100644 --- a/webapp/src/dogma/features/file/FileList.tsx +++ b/webapp/src/dogma/features/file/FileList.tsx @@ -58,7 +58,7 @@ const FileList = ({ fontWeight={'semibold'} href={ info.row.original.type === 'DIRECTORY' - ? `${directoryPath}${info.getValue()}` + ? `${directoryPath}/${info.getValue()}` : `${slug}/${info.getValue()}` } > diff --git a/webapp/tests/dogma/feature/file/FileList.test.tsx b/webapp/tests/dogma/feature/file/FileList.test.tsx index c802ecc7b1..fe6c341257 100644 --- a/webapp/tests/dogma/feature/file/FileList.test.tsx +++ b/webapp/tests/dogma/feature/file/FileList.test.tsx @@ -78,11 +78,11 @@ describe('FileList', () => { ); }); - it('has `${directoryPath}${folderName.slice(1)}` on the view icon when the type is a directory', () => { + it('has `${directoryPath}/${folderName.slice(1)}` on the view icon when the type is a directory', () => { const { container } = renderWithProviders(); const actionCell = container.querySelector('tbody').lastChild.firstChild.lastChild; const folderName = '/mydir'; - expect(actionCell).toHaveAttribute('href', `${expectedProps.directoryPath}${folderName.slice(1)}`); + expect(actionCell).toHaveAttribute('href', `${expectedProps.directoryPath}/${folderName.slice(1)}`); }); it('links to `${projectName}/repos/${repoName}/files/head{fileName}` when the type is non-directory', () => { @@ -123,11 +123,11 @@ describe('FileList', () => { expect(expectedProps.copySupport.handleAsCurlCommand).toHaveBeenCalledTimes(1); }); - it('links to `${directoryPath}${folderName.slice(1)}` when the type is a directory', () => { + it('links to `${directoryPath}/${folderName.slice(1)}` when the type is a directory', () => { const { container } = renderWithProviders(); const firstCell = container.querySelector('tbody').lastChild.firstChild.firstChild; const folderName = '/mydir'; - expect(firstCell).toHaveAttribute('href', `${expectedProps.directoryPath}${folderName.slice(1)}`); + expect(firstCell).toHaveAttribute('href', `${expectedProps.directoryPath}/${folderName.slice(1)}`); }); it('calls handleCopyApiUrl when copy API URL button is clicked', () => { @@ -158,10 +158,10 @@ describe('FileList', () => { expect(expectedProps.copySupport.handleAsCurlCommand).toHaveBeenCalledTimes(1); }); - it('links to `${directoryPath}${folderName.slice(1)}` when the type is a directory', () => { + it('links to `${directoryPath}/${folderName.slice(1)}` when the type is a directory', () => { const { container } = renderWithProviders(); const firstCell = container.querySelector('tbody').lastChild.firstChild.firstChild; const folderName = '/mydir'; - expect(firstCell).toHaveAttribute('href', `${expectedProps.directoryPath}${folderName.slice(1)}`); + expect(firstCell).toHaveAttribute('href', `${expectedProps.directoryPath}/${folderName.slice(1)}`); }); }); diff --git a/xds/src/test/java/com/linecorp/centraldogma/xds/group/v1/XdsGroupServiceTest.java b/xds/src/test/java/com/linecorp/centraldogma/xds/group/v1/XdsGroupServiceTest.java index 9ae109300f..def113ca10 100644 --- a/xds/src/test/java/com/linecorp/centraldogma/xds/group/v1/XdsGroupServiceTest.java +++ b/xds/src/test/java/com/linecorp/centraldogma/xds/group/v1/XdsGroupServiceTest.java @@ -30,6 +30,7 @@ import com.linecorp.armeria.common.AggregatedHttpResponse; import com.linecorp.armeria.common.HttpHeaderNames; import com.linecorp.armeria.common.HttpStatus; +import com.linecorp.centraldogma.server.CentralDogmaBuilder; import com.linecorp.centraldogma.testing.junit.CentralDogmaExtension; import com.linecorp.centraldogma.xds.group.v1.XdsGroupServiceGrpc.XdsGroupServiceBlockingStub; @@ -39,7 +40,15 @@ final class XdsGroupServiceTest { @RegisterExtension - static final CentralDogmaExtension dogma = new CentralDogmaExtension(); + static final CentralDogmaExtension dogma = new CentralDogmaExtension() { + @Override + protected void configure(CentralDogmaBuilder builder) { + // To see if it's working when the web app is enabled. + // When webAppEnabled is true, we add additional services that might affect service bind path. + // https://github.com/line/centraldogma/blob/a4e58931ac98e8b6e9e470033ba04ee60180b135/server/src/main/java/com/linecorp/centraldogma/server/CentralDogma.java#L863 + builder.webAppEnabled(true); + } + }; @Test void createGroupViaHttp() {