diff --git a/config/config.go b/config/config.go index b942f7d1..94d1e6d8 100644 --- a/config/config.go +++ b/config/config.go @@ -1,8 +1,25 @@ package config +import "infini.sh/framework/core/config" + type AppConfig struct { - Elasticsearch string `config:"elasticsearch"` - UILocalPath string `config:"ui_path"` - UILocalEnabled bool `config:"ui_local"` - UIVFSEnabled bool `config:"ui_vfs"` + Elasticsearch string `config:"elasticsearch"` + UI UIConfig `config:"ui"` + Network config.NetworkConfig `config:"network"` + TLSConfig config.TLSConfig `config:"tls"` +} + +type UIConfig struct { + Enabled bool `config:"enabled"` + LocalPath string `config:"path"` + LocalEnabled bool `config:"local"` + VFSEnabled bool `config:"vfs"` + APIEndpoint string `config:"api_endpoint"` +} + +func (config *AppConfig) GetSchema() string { + if config.TLSConfig.TLSEnabled { + return "https" + } + return "http" } diff --git a/main.go b/main.go index eb8033fa..14c9b7ff 100644 --- a/main.go +++ b/main.go @@ -3,9 +3,11 @@ package main import ( "errors" _ "expvar" + "fmt" "infini.sh/framework" "infini.sh/framework/core/elastic" "infini.sh/framework/core/env" + "infini.sh/framework/core/global" "infini.sh/framework/core/module" "infini.sh/framework/core/orm" "infini.sh/framework/modules" @@ -50,12 +52,14 @@ func main() { appConfig = &config.AppConfig{ Elasticsearch: "default", - UILocalPath: ".public", - UIVFSEnabled: true, - UILocalEnabled: true, + UI: config.UIConfig{ + LocalPath: ".public", + VFSEnabled: true, + LocalEnabled: true, + }, } - ok, err := env.ParseConfig("search-center", appConfig) + ok, err := env.ParseConfig("web", appConfig) if err != nil { panic(err) } @@ -74,6 +78,12 @@ func main() { // global.Env().SystemConfig.APIConfig.CrossDomain.AllowedOrigins= // append(global.Env().SystemConfig.APIConfig.CrossDomain.AllowedOrigins,uiConfig.NetworkConfig.GetBindingAddr()) //} + apiConfig := global.Env().SystemConfig.APIConfig + if len(apiConfig.CrossDomain.AllowedOrigins) == 0 { + apiConfig.CrossDomain.AllowedOrigins = []string{ + fmt.Sprintf("%s://%s", appConfig.GetSchema(), apiConfig.NetworkConfig.GetPublishAddr()), + } + } //start each module, with enabled provider module.Start() diff --git a/ui.go b/ui.go index 57935a9b..460cf2d1 100644 --- a/ui.go +++ b/ui.go @@ -2,7 +2,10 @@ package main import ( "fmt" + "infini.sh/framework/core/global" "net/http" + "src/github.com/segmentio/encoding/json" + "strings" public "infini.sh/search-center/.public" @@ -22,12 +25,25 @@ type UI struct { func (h UI) InitUI() { - vfs.RegisterFS(public.StaticFS{StaticFolder: h.Config.UILocalPath, TrimLeftPath: h.Config.UILocalPath, CheckLocalFirst: h.Config.UILocalEnabled, SkipVFS: !h.Config.UIVFSEnabled}) + vfs.RegisterFS(public.StaticFS{StaticFolder: h.Config.UI.LocalPath, TrimLeftPath: h.Config.UI.LocalPath, CheckLocalFirst: h.Config.UI.LocalEnabled, SkipVFS: !h.Config.UI.VFSEnabled}) ui.HandleUI("/", vfs.FileServer(vfs.VFS())) uiapi.Init(h.Config) + var apiEndpoint = h.Config.UI.APIEndpoint + if strings.TrimSpace(apiEndpoint) == "" { + apiConfig := &global.Env().SystemConfig.APIConfig + apiEndpoint = fmt.Sprintf("%s://%s", apiConfig.GetSchema(), apiConfig.NetworkConfig.GetPublishAddr()) + } + + ui.HandleUIFunc("/config", func(w http.ResponseWriter, req *http.Request){ + buf, _ := json.Marshal(util.MapStr{ + "api_endpoint": apiEndpoint, + }) + w.Write(buf) + }) + ui.HandleUIFunc("/api/", func(w http.ResponseWriter, req *http.Request) { log.Warn("api: ", req.URL, " not implemented") request, err := h.GetRawBody(req) diff --git a/web/config/config.js b/web/config/config.js index 1f1ea155..b5990902 100644 --- a/web/config/config.js +++ b/web/config/config.js @@ -50,7 +50,7 @@ export default { define: { APP_TYPE: process.env.APP_TYPE || '', ENV: process.env.NODE_ENV, - API_ENDPOINT: 'http://localhost:2900', + API_ENDPOINT: process.env.API_ENDPOINT || '', }, // 路由配置 routes: pageRoutes, @@ -125,7 +125,7 @@ export default { }, copy:[ - './src/assets/favicon.ico' + './src/assets/favicon.ico', ], history: 'hash', // exportStatic: { diff --git a/web/src/assets/elasticsearch.ico b/web/src/assets/elasticsearch.ico new file mode 100644 index 00000000..41320478 Binary files /dev/null and b/web/src/assets/elasticsearch.ico differ diff --git a/web/src/components/GlobalHeader/RightContent.js b/web/src/components/GlobalHeader/RightContent.js index 576d3117..b80d1c35 100644 --- a/web/src/components/GlobalHeader/RightContent.js +++ b/web/src/components/GlobalHeader/RightContent.js @@ -185,7 +185,7 @@ export default class GlobalHeaderRight extends PureComponent { bottomLeft: false, topLeft: false, }}> */} - 0 && - {/* */} + />} ); diff --git a/web/src/components/GlobalHeader/index.js b/web/src/components/GlobalHeader/index.js index ec015901..67f889ca 100644 --- a/web/src/components/GlobalHeader/index.js +++ b/web/src/components/GlobalHeader/index.js @@ -40,9 +40,6 @@ export default class GlobalHeader extends PureComponent { }; render() { const { collapsed, isMobile, logo, clusterVisible, clusterList, selectedCluster } = this.props; - if(clusterList.length == 0){ - return null - } return (
{isMobile && ( @@ -55,7 +52,8 @@ export default class GlobalHeader extends PureComponent { type={collapsed ? 'menu-unfold' : 'menu-fold'} onClick={this.toggle} /> - 0 && + }
); diff --git a/web/src/components/kibana/console/components/Console.tsx b/web/src/components/kibana/console/components/Console.tsx index e21af7ec..489c09d5 100644 --- a/web/src/components/kibana/console/components/Console.tsx +++ b/web/src/components/kibana/console/components/Console.tsx @@ -87,7 +87,7 @@ const ConsoleWrapper = ({ - + {lastDatum?.request.header} diff --git a/web/src/pages/DevTool/Console.tsx b/web/src/pages/DevTool/Console.tsx index 823573b4..c4d08384 100644 --- a/web/src/pages/DevTool/Console.tsx +++ b/web/src/pages/DevTool/Console.tsx @@ -139,10 +139,14 @@ export const ConsoleUI = ({selectedCluster, return cm; }, [clusterList, clusterStatus]) const initialDefaultState = ()=>{ - const defaultActiveKey = `${selectedCluster.id}:${new Date().valueOf()}`; - const defaultState = selectedCluster? { + let defaultCluster = selectedCluster; + if(!defaultCluster.id){ + defaultCluster = clusterList[0] ; + } + const defaultActiveKey = `${defaultCluster.id || ''}:${new Date().valueOf()}`; + const defaultState = defaultCluster? { panes:[{ - key: defaultActiveKey, cluster_id: selectedCluster.id, title: selectedCluster.name + key: defaultActiveKey, cluster_id: defaultCluster.id, title: defaultCluster.name }], activeKey: defaultActiveKey, }: {panes:[],activeKey:''}; diff --git a/web/src/pages/DevTool/console_tab_title.tsx b/web/src/pages/DevTool/console_tab_title.tsx index b92b2890..99121e07 100644 --- a/web/src/pages/DevTool/console_tab_title.tsx +++ b/web/src/pages/DevTool/console_tab_title.tsx @@ -1,10 +1,10 @@ import {useState, useRef, useEffect} from 'react'; import './console_tab_title.scss'; -import ElasticSvg from '@/assets/elasticsearch.svg'; +import ElasticImg from '@/assets/elasticsearch.ico'; import {Icon} from 'antd'; const ElasticIcon = () => ( - + ); interface TabTitleProps { diff --git a/web/src/services/common.js b/web/src/services/common.js index 16d80725..a8f15517 100644 --- a/web/src/services/common.js +++ b/web/src/services/common.js @@ -1,5 +1,34 @@ -export const pathPrefix = (API_ENDPOINT || '') + '/_search-center'; +import $ from 'jquery'; +function getConfig(){ + const options = { + url: "/config", + cache: false, + type: 'GET', + dataType: 'json', // disable automatic guessing + async: false, + }; + let result = {} + try{ + const text = $.ajax(options).responseText; + result = JSON.parse(text); + }catch(e){ + console.warn('failed get config data') + } + return result; + +} +const {api_endpoint} = getConfig(); + +let apiEndpoint = api_endpoint; +if(!apiEndpoint){ + apiEndpoint = API_ENDPOINT; + if(!API_ENDPOINT){ + apiEndpoint = `${location.protocol}//${location.hostname}:2900` + } +} + +export const pathPrefix = (apiEndpoint || '') + '/_search-center'; export function buildQueryArgs(params){ let argsStr = ''; for(let key in params){ @@ -14,4 +43,4 @@ export function buildQueryArgs(params){ return argsStr; } -export const ESPrefix = (API_ENDPOINT || '') + '/elasticsearch'; \ No newline at end of file +export const ESPrefix = (apiEndpoint || '') + '/elasticsearch'; \ No newline at end of file