Skip to content

Commit

Permalink
feat: add BKSharedResBaseJSURL conf
Browse files Browse the repository at this point in the history
  • Loading branch information
ifooth committed Jul 2, 2024
1 parent 419d2cf commit dd3113f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
2 changes: 1 addition & 1 deletion bcs-services/bcs-bscp/cmd/ui/etc/bscp-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ web:
host: ""
route_prefix: ""
preferred_domains: ""
bk_shared_res_url: ""
etcd:
endpoints: 127.0.0.1:2379
ca: ""
Expand All @@ -23,5 +22,6 @@ frontend_conf:
bk_cmdb_host: ""
bscp_api_url: ""
bk_nodeman_host: ""
bk_shared_res_url: ""
helper: ""
enable_bk_notice: false
2 changes: 1 addition & 1 deletion bcs-services/bcs-bscp/cmd/ui/service/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ func (s *WebServer) subRouter() http.Handler {
RunEnv: config.G.Base.RunEnv,
ProxyAPI: shouldProxyAPI,
SiteURL: config.G.Web.RoutePrefix,
BKSharedResBaseJSURL: config.G.Web.BKSharedResBaseJSURL,
APIURL: config.G.Frontend.Host.BSCPAPIURL,
IAMHost: config.G.Frontend.Host.BKIAMHost,
CMDBHost: config.G.Frontend.Host.BKCMDBHost,
BKSharedResBaseJSURL: config.G.Frontend.Host.BKSharedResBaseJSURL,
EnableBKNotice: config.G.Frontend.EnableBKNotice,
Helper: config.G.Frontend.Helper,
FeedAddr: config.G.Base.FeedAddr,
Expand Down
2 changes: 1 addition & 1 deletion bcs-services/bcs-bscp/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c *Configuration) init() error {
if err := c.Web.init(); err != nil {
return err
}
if err := c.Web.initResBaseJSURL(c.Base.AppCode); err != nil {
if err := c.Frontend.initResBaseJSURL(c.Base.AppCode); err != nil {
return err
}

Expand Down
34 changes: 30 additions & 4 deletions bcs-services/bcs-bscp/pkg/config/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@
// Package config xxx
package config

import (
"fmt"
"net/url"
"path"
)

// HostConf host conf
type HostConf struct {
BKIAMHost string `yaml:"bk_iam_host"` // 权限中心
BKCMDBHost string `yaml:"bk_cmdb_host"` // 配置平台
BSCPAPIURL string `yaml:"bscp_api_url"` // bscp api地址
BKNODEMANHOST string `yaml:"bk_nodeman_host"` // 节点管理地址
BKIAMHost string `yaml:"bk_iam_host"` // 权限中心
BKCMDBHost string `yaml:"bk_cmdb_host"` // 配置平台
BSCPAPIURL string `yaml:"bscp_api_url"` // bscp api地址
BKNODEMANHOST string `yaml:"bk_nodeman_host"` // 节点管理地址
BKSharedResURL string `yaml:"bk_shared_res_url"` // 对应运维公共变量bkSharedResUrl, PaaS环境变量BKPAAS_SHARED_RES_URL
BKSharedResBaseJSURL string `yaml:"-"` // 规则是${bkSharedResUrl}/${目录名 aks app_code}/base.js
}

// FrontendConf docs and host conf
Expand All @@ -37,3 +45,21 @@ func defaultUIConf() *FrontendConf {
}
return c
}

func (c *FrontendConf) initResBaseJSURL(appCode string) error {
if c.Host.BKSharedResURL == "" {
return nil
}
if appCode == "" {
return fmt.Errorf("initResBaseJSURL: app_code is required")
}

u, err := url.Parse(c.Host.BKSharedResURL)
if err != nil {
return err
}
u.Path = path.Join(u.Path, appCode, "base.js")

c.Host.BKSharedResBaseJSURL = u.String()
return nil
}
29 changes: 4 additions & 25 deletions bcs-services/bcs-bscp/pkg/config/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@
package config

import (
"fmt"
"net/url"
"path"
)

// WebConf web 相关配置
type WebConf struct {
Host string `yaml:"host"`
RoutePrefix string `yaml:"route_prefix"` // vue路由, 静态资源前缀
PreferredDomains string `yaml:"preferred_domains"`
BaseURL *url.URL `yaml:"-"`
BKSharedResURL string `yaml:"bk_shared_res_url"` // 对应运维公共变量bkSharedResUrl, PaaS环境变量BKPAAS_SHARED_RES_URL
BKSharedResBaseJSURL string `yaml:"-"` // 规则是${bkSharedResUrl}/${目录名 aks app_code}/base.js
Host string `yaml:"host"`
RoutePrefix string `yaml:"route_prefix"` // vue路由, 静态资源前缀
PreferredDomains string `yaml:"preferred_domains"`
BaseURL *url.URL `yaml:"-"`
}

// init 初始化
Expand All @@ -40,24 +37,6 @@ func (c *WebConf) init() error {
return nil
}

func (c *WebConf) initResBaseJSURL(appCode string) error {
if c.BKSharedResURL == "" {
return nil
}
if appCode == "" {
return fmt.Errorf("initResBaseJSURL: app_code is required")
}

u, err := url.Parse(c.BKSharedResURL)
if err != nil {
return err
}
u.Path = path.Join(u.Path, appCode, "base.js")

c.BKSharedResBaseJSURL = u.String()
return nil
}

// defaultWebConf 默认配置
func defaultWebConf() *WebConf {
c := &WebConf{
Expand Down

0 comments on commit dd3113f

Please sign in to comment.