11import DetailsSection from './integrations/DetailsSection' ;
22import HeaderSection from './integrations/HeaderSection' ;
33import IntegrationsService from './integrations/IntegrationsService' ;
4- import { fancyConsoleLog , setMetaContent } from './shared/common' ;
4+ import { detectTopicFromUrl , fancyConsoleLog , setMetaContent } from './shared/common' ;
55
66import '../css/steps.css' ;
77
8- /**
9- * @param {URL } url
10- * @returns {?string }
11- */
12- function detectStepFromUrl ( url ) {
13- let path = url . pathname ;
14- if ( path . match ( / s t e p s \/ ? $ / ) ) {
15- path = `${ path . replace ( / \/ $ / , '' ) } /${ url . searchParams . get ( 'step' ) } ` ;
16- }
17-
18- const match = path . match ( / s t e p s \/ ( .+ ) $ / ) ;
19- if ( match ) {
20- return match [ 1 ] ;
21- }
22- return null ;
23- }
24-
258const url = new URL ( document . location . href ) ;
26- const stepFilter = detectStepFromUrl ( url ) ;
9+ const stepFilter = detectTopicFromUrl ( url , 'integrations/steps' , 'step' ) ;
2710
2811const header = new HeaderSection ( ) ;
2912const details = new DetailsSection ( ) ;
3013
31- IntegrationsService . loadIntegrations ( ) . then ( ( integrations ) => {
14+ ( async ( ) => {
15+ const integrations = await IntegrationsService . loadIntegrations ( ) ;
3216 if ( ! stepFilter || ! ( stepFilter in integrations . steps ) ) {
3317 window . location . href = '/integrations' ;
3418 } else {
@@ -53,8 +37,18 @@ IntegrationsService.loadIntegrations().then((integrations) => {
5337 header . render ( integrations , step ) ;
5438 details . render ( integrations , step ) ;
5539
40+ const proxyAvailable = await fetch ( '/integrations-proxy' )
41+ . then ( ( proxyResponse ) => proxyResponse . ok )
42+ . catch ( ( ) => false ) ;
43+
44+ if ( ! proxyAvailable ) {
45+ document . querySelectorAll ( 'a[href^="/integrations"]' ) . forEach ( ( link ) => {
46+ link . href = `/integrations/step?step=${ link . getAttribute ( 'href' ) . replace ( / ^ .* \/ i n t e g r a t i o n s \/ s t e p s \/ / , '' ) } ` ;
47+ } ) ;
48+ }
49+
5650 fancyConsoleLog ( `Bitrise.io Integrations: ${ step . title } ` ) ;
5751 }
58- } ) ;
52+ } ) ( ) ;
5953
6054if ( import . meta. webpackHot ) import . meta. webpackHot . accept ( ) ;
0 commit comments