8
8
import org .springframework .util .StreamUtils ;
9
9
import org .springframework .web .bind .annotation .RequestMapping ;
10
10
11
+ import javax .servlet .http .HttpServletRequest ;
11
12
import javax .servlet .http .HttpServletResponse ;
12
13
import java .io .IOException ;
13
14
import java .nio .charset .Charset ;
@@ -33,12 +34,13 @@ public class VoyagerController
33
34
private String voyagerCdnVersion ;
34
35
35
36
@ RequestMapping (value = "${voyager.mapping:/voyager}" )
36
- public void voyager (HttpServletResponse response ) throws IOException
37
+ public void voyager (HttpServletRequest request , HttpServletResponse response ) throws IOException
37
38
{
39
+ String contextPath = request .getContextPath ();
38
40
response .setContentType ("text/html; charset=UTF-8" );
39
41
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" ;
42
44
43
45
if (voyagerCdnEnabled && StringUtils .isNotBlank (voyagerCdnVersion )) {
44
46
voyagerCssUrl = "//apis.guru/graphql-voyager/releases/" + voyagerCdnVersion + "/voyager.css" ;
@@ -47,10 +49,11 @@ public void voyager(HttpServletResponse response) throws IOException
47
49
48
50
String template = StreamUtils .copyToString (new ClassPathResource ("voyager.html" ).getInputStream (), Charset .defaultCharset ());
49
51
Map <String , String > replacements = new HashMap <>();
50
- replacements .put ("graphqlEndpoint" , graphqlEndpoint );
52
+ replacements .put ("graphqlEndpoint" , contextPath + graphqlEndpoint );
51
53
replacements .put ("pageTitle" , pageTitle );
52
54
replacements .put ("voyagerCssUrl" , voyagerCssUrl );
53
55
replacements .put ("voyagerJsUrl" , voyagerJsUrl );
56
+ replacements .put ("contextPath" , contextPath );
54
57
55
58
response .getOutputStream ().write (StrSubstitutor .replace (template , replacements ).getBytes (Charset .defaultCharset ()));
56
59
}
0 commit comments