Skip to content

Commit

Permalink
fix: move string to constant
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Oct 27, 2023
1 parent 987e9d3 commit 9f6b20a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cmd/extension/extension_admin_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/FriendsOfShopware/shopware-cli/logging"
)

const schemeHostSeparator = "://"

var (
hostRegExp = regexp.MustCompile(`(?m)host:\s'.*,`)
portRegExp = regexp.MustCompile(`(?m)port:\s.*,`)
Expand Down Expand Up @@ -147,9 +149,9 @@ var extensionAdminWatchCmd = &cobra.Command{
bodyStr = hostRegExp.ReplaceAllString(bodyStr, "host: '"+browserUrl.Host+"',")
bodyStr = portRegExp.ReplaceAllString(bodyStr, "port: "+browserPort+",")
bodyStr = schemeRegExp.ReplaceAllString(bodyStr, "scheme: '"+browserUrl.Scheme+"',")
bodyStr = schemeAndHttpHostRegExp.ReplaceAllString(bodyStr, "schemeAndHttpHost: '"+browserUrl.Scheme+"://"+browserUrl.Host+"',")
bodyStr = uriRegExp.ReplaceAllString(bodyStr, "uri: '"+browserUrl.Scheme+"://"+browserUrl.Host+targetShopUrl.Path+"/admin',")
bodyStr = assetPathRegExp.ReplaceAllString(bodyStr, "assetPath: '"+browserUrl.Scheme+"://"+browserUrl.Host+targetShopUrl.Path+"'")
bodyStr = schemeAndHttpHostRegExp.ReplaceAllString(bodyStr, "schemeAndHttpHost: '"+browserUrl.Scheme+schemeHostSeparator+browserUrl.Host+"',")
bodyStr = uriRegExp.ReplaceAllString(bodyStr, "uri: '"+browserUrl.Scheme+schemeHostSeparator+browserUrl.Host+targetShopUrl.Path+"/admin',")
bodyStr = assetPathRegExp.ReplaceAllString(bodyStr, "assetPath: '"+browserUrl.Scheme+schemeHostSeparator+browserUrl.Host+targetShopUrl.Path+"'")

bodyStr = assetRegExp.ReplaceAllStringFunc(bodyStr, func(s string) string {
firstPart := ""
Expand Down Expand Up @@ -194,7 +196,7 @@ var extensionAdminWatchCmd = &cobra.Command{
if req.URL.Path == targetShopUrl.Path+"/api/_info/config" {
logging.FromContext(cmd.Context()).Debugf("intercept plugins call")

proxyReq, _ := http.NewRequest("GET", targetShopUrl.Scheme+"://"+targetShopUrl.Host+req.URL.Path, nil)
proxyReq, _ := http.NewRequest("GET", targetShopUrl.Scheme+schemeHostSeparator+targetShopUrl.Host+req.URL.Path, nil)

proxyReq.Header.Set("Authorization", req.Header.Get("Authorization"))

Expand Down

0 comments on commit 9f6b20a

Please sign in to comment.