@@ -15,6 +15,8 @@ import (
1515 "github.com/Shopify/themekit/src/release"
1616)
1717
18+ const themeKitPasswordPrefix = "shptka_"
19+
1820var (
1921 // ErrConnectionIssue is an error that is thrown when a very specific error is
2022 // returned from our http request that usually implies bad connections.
2729 httpClient = & http.Client {
2830 Timeout : 30 * time .Second ,
2931 }
32+ themeKitAccessURL = "https://theme-kit-access.shopifyapps.com/cli"
3033)
3134
3235type proxyHandler func (* http.Request ) (* url.URL , error )
@@ -103,7 +106,15 @@ func (client *HTTPClient) Delete(path string, headers map[string]string) (*http.
103106
104107// do will issue an authenticated json request to shopify.
105108func (client * HTTPClient ) do (method , path string , body interface {}, headers map [string ]string ) (* http.Response , error ) {
106- req , err := http .NewRequest (method , client .baseURL .String ()+ path , nil )
109+ appBaseURL := client .baseURL .String ()
110+
111+ // redirect to Theme Kit Access
112+ if strings .HasPrefix (client .password , themeKitPasswordPrefix ) {
113+ appBaseURL = themeKitAccessURL
114+ }
115+
116+ req , err := http .NewRequest (method , appBaseURL + path , nil )
117+
107118 if err != nil {
108119 return nil , err
109120 }
@@ -112,6 +123,9 @@ func (client *HTTPClient) do(method, path string, body interface{}, headers map[
112123 req .Header .Add ("Content-Type" , "application/json" )
113124 req .Header .Add ("Accept" , "application/json" )
114125 req .Header .Add ("User-Agent" , fmt .Sprintf ("go/themekit (%s; %s; %s)" , runtime .GOOS , runtime .GOARCH , release .ThemeKitVersion .String ()))
126+ if strings .HasPrefix (client .password , themeKitPasswordPrefix ) {
127+ req .Header .Add ("X-Shopify-Shop" , client .domain )
128+ }
115129 for label , value := range headers {
116130 req .Header .Add (label , value )
117131 }
0 commit comments