Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 95b764b

Browse files
authored
Merge pull request #144 from graphql-java-kickstart/bugfix/125-voyager-context-path
Add contextpath to html when serving voyager (fix #125)
2 parents 6320bbd + 539b207 commit 95b764b

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

voyager-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/voyager/boot/VoyagerController.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.util.StreamUtils;
99
import org.springframework.web.bind.annotation.RequestMapping;
1010

11+
import javax.servlet.http.HttpServletRequest;
1112
import javax.servlet.http.HttpServletResponse;
1213
import java.io.IOException;
1314
import java.nio.charset.Charset;
@@ -33,12 +34,13 @@ public class VoyagerController
3334
private String voyagerCdnVersion;
3435

3536
@RequestMapping(value = "${voyager.mapping:/voyager}")
36-
public void voyager(HttpServletResponse response) throws IOException
37+
public void voyager(HttpServletRequest request, HttpServletResponse response) throws IOException
3738
{
39+
String contextPath = request.getContextPath();
3840
response.setContentType("text/html; charset=UTF-8");
3941

40-
String voyagerCssUrl = "/vendor/voyager.css";
41-
String voyagerJsUrl = "/vendor/voyager.min.js";
42+
String voyagerCssUrl = contextPath + "/vendor/voyager.css";
43+
String voyagerJsUrl = contextPath + "/vendor/voyager.min.js";
4244

4345
if (voyagerCdnEnabled && StringUtils.isNotBlank(voyagerCdnVersion)) {
4446
voyagerCssUrl = "//apis.guru/graphql-voyager/releases/" + voyagerCdnVersion + "/voyager.css";
@@ -47,10 +49,11 @@ public void voyager(HttpServletResponse response) throws IOException
4749

4850
String template = StreamUtils.copyToString(new ClassPathResource("voyager.html").getInputStream(), Charset.defaultCharset());
4951
Map<String, String> replacements = new HashMap<>();
50-
replacements.put("graphqlEndpoint", graphqlEndpoint);
52+
replacements.put("graphqlEndpoint", contextPath + graphqlEndpoint);
5153
replacements.put("pageTitle", pageTitle);
5254
replacements.put("voyagerCssUrl", voyagerCssUrl);
5355
replacements.put("voyagerJsUrl", voyagerJsUrl);
56+
replacements.put("contextPath", contextPath);
5457

5558
response.getOutputStream().write(StrSubstitutor.replace(template, replacements).getBytes(Charset.defaultCharset()));
5659
}

voyager-spring-boot-autoconfigure/src/main/resources/voyager.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<script src="/vendor/react.min.js"></script>
5-
<script src="/vendor/react-dom.min.js"></script>
4+
<script src="${contextPath}/vendor/react.min.js"></script>
5+
<script src="${contextPath}/vendor/react-dom.min.js"></script>
66

77
<link rel="stylesheet" href="${voyagerCssUrl}" />
88
<script src="${voyagerJsUrl}"></script>

0 commit comments

Comments
 (0)