88import org .springframework .util .StreamUtils ;
99import org .springframework .web .bind .annotation .RequestMapping ;
1010
11+ import javax .servlet .http .HttpServletRequest ;
1112import javax .servlet .http .HttpServletResponse ;
1213import java .io .IOException ;
1314import 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 }
0 commit comments