1
1
package graphql .kickstart .autoconfigure .editor .altair ;
2
2
3
+ import static java .lang .Integer .parseInt ;
4
+ import static java .util .Objects .nonNull ;
5
+ import static org .apache .commons .lang3 .StringUtils .isNumeric ;
6
+
3
7
import com .fasterxml .jackson .core .JsonProcessingException ;
4
8
import com .fasterxml .jackson .databind .ObjectMapper ;
5
9
import graphql .kickstart .autoconfigure .editor .PropertyGroupReader ;
13
17
import javax .annotation .PostConstruct ;
14
18
import javax .servlet .http .HttpServletRequest ;
15
19
import javax .servlet .http .HttpServletResponse ;
20
+ import lombok .extern .slf4j .Slf4j ;
21
+ import lombok .val ;
16
22
import org .apache .commons .lang3 .StringUtils ;
17
23
import org .apache .commons .text .StringSubstitutor ;
18
24
import org .springframework .beans .factory .annotation .Autowired ;
25
31
import org .springframework .web .bind .annotation .RequestParam ;
26
32
27
33
/** @author Moncef AOUDIA */
34
+ @ Slf4j
28
35
@ Controller
29
36
public class AltairController {
30
37
31
- private static final String CDN_UNPKG = "//unpkg.com /" ;
38
+ private static final String CDN_JSDELIVR_NET_NPM = "//cdn.jsdelivr.net/npm /" ;
32
39
private static final String ALTAIR = "altair-static" ;
33
40
34
41
@ Autowired private AltairProperties altairProperties ;
@@ -95,14 +102,24 @@ private Map<String, String> getReplacements(
95
102
replacements .put (
96
103
"altairLogoUrl" , getResourceUrl ("assets/img/logo_350.svg" , "assets/img/logo_350.svg" ));
97
104
replacements .put ("altairCssUrl" , getResourceUrl ("styles.css" , "styles.css" ));
98
- replacements .put ("altairMainJsUrl" , getResourceUrl ("main.js" , "main.js" ));
99
- replacements .put ("altairPolyfillsJsUrl" , getResourceUrl ("polyfills.js" , "polyfills.js" ));
100
- replacements .put ("altairRuntimeJsUrl" , getResourceUrl ("runtime.js" , "runtime.js" ));
105
+
106
+ val suffix = isJsSuffixAdded () ? "-es2018.js" : ".js" ;
107
+ replacements .put ("altairMainJsUrl" , getResourceUrl ("main-es2018.js" , "main" + suffix ));
108
+ replacements .put ("altairPolyfillsJsUrl" , getResourceUrl ("polyfills-es2018.js" , "polyfills" + suffix ));
109
+ replacements .put ("altairRuntimeJsUrl" , getResourceUrl ("runtime-es2018.js" , "runtime" + suffix ));
101
110
replacements .put ("props" , props );
102
111
replacements .put ("headers" , headers );
103
112
return replacements ;
104
113
}
105
114
115
+ private boolean isJsSuffixAdded () {
116
+ if (nonNull (altairProperties .getCdn ().getVersion ())) {
117
+ String [] versionValues = altairProperties .getCdn ().getVersion ().split ("\\ ." );
118
+ return isNumeric (versionValues [0 ]) && parseInt (versionValues [0 ]) >= 4 ;
119
+ }
120
+ return false ;
121
+ }
122
+
106
123
private String getResourceUrl (String staticFileName , String cdnUrl ) {
107
124
if (altairProperties .getCdn ().isEnabled () && StringUtils .isNotBlank (cdnUrl )) {
108
125
return cdnUrl ;
@@ -111,7 +128,7 @@ private String getResourceUrl(String staticFileName, String cdnUrl) {
111
128
}
112
129
113
130
private String joinJsUnpkgPath (String library , String cdnVersion , String cdnFileName ) {
114
- return CDN_UNPKG + library + "@" + cdnVersion + "/" + cdnFileName ;
131
+ return CDN_JSDELIVR_NET_NPM + library + "@" + cdnVersion + "/" + cdnFileName ;
115
132
}
116
133
117
134
private String constructGraphQlEndpoint (
0 commit comments