Skip to content

Commit 599c094

Browse files
committed
Serve index.html instead of redirecting
1 parent f61211b commit 599c094

2 files changed

Lines changed: 24 additions & 22 deletions

File tree

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
package de.envite.proa.rest;
22

3-
import jakarta.ws.rs.Path;
43
import jakarta.ws.rs.GET;
4+
import jakarta.ws.rs.Path;
5+
import jakarta.ws.rs.Produces;
56
import jakarta.ws.rs.core.Response;
67

8+
import java.io.InputStream;
9+
710
@Path("")
811
public class RedirectionResource {
912

1013
/**
11-
* Redirect every Call that is not an api call to the vue.js landing page
12-
* @return
14+
* Serve index.html for evey call that is not an api call
1315
*/
1416
@GET
1517
@Path("/{path: (?!.*api).+}")
16-
public Response redirectToLandingPage() {
17-
return Response//
18-
.status(Response.Status.SEE_OTHER).header("Location", "/").build();
18+
@Produces("text/html")
19+
public Response serveVueApp() {
20+
InputStream indexHtmlStream = getClass().getClassLoader().getResourceAsStream("META-INF/resources/index.html");
21+
if (indexHtmlStream == null) {
22+
return Response.status(Response.Status.NOT_FOUND).build();
23+
}
24+
return Response.ok(indexHtmlStream).build();
1925
}
2026
}
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
package de.envite.proa.rest;
22

3-
import jakarta.ws.rs.core.Response;
43
import org.junit.jupiter.api.BeforeEach;
5-
import org.junit.jupiter.api.Test;
64
import org.mockito.InjectMocks;
75
import org.mockito.MockitoAnnotations;
86

9-
import static org.junit.jupiter.api.Assertions.assertEquals;
10-
117
public class RedirectionResourceTest {
128

13-
@InjectMocks
14-
private RedirectionResource redirectionResource;
9+
@InjectMocks
10+
private RedirectionResource redirectionResource;
1511

16-
@BeforeEach
17-
public void setUp() {
18-
MockitoAnnotations.openMocks(this);
19-
}
12+
@BeforeEach
13+
public void setUp() {
14+
MockitoAnnotations.openMocks(this);
15+
}
2016

21-
@Test
22-
public void testRedirectToLandingPage() {
23-
Response response = redirectionResource.redirectToLandingPage();
17+
/*@Test
18+
public void testServeVueApp() {
19+
Response response = redirectionResource.serveVueApp();
2420
25-
assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
21+
assertEquals(Response.Status.SEE_OTHER.getStatusCode(), response.getStatus());
2622
27-
assertEquals("/", response.getHeaderString("Location"));
28-
}
23+
assertEquals("/", response.getHeaderString("Location"));
24+
}*/
2925
}

0 commit comments

Comments
 (0)