console and cors
This commit is contained in:
parent
b8e6c8a579
commit
dc4202ba3a
|
@ -1,8 +1,25 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
|
import "infini.sh/framework/core/config"
|
||||||
|
|
||||||
type AppConfig struct {
|
type AppConfig struct {
|
||||||
Elasticsearch string `config:"elasticsearch"`
|
Elasticsearch string `config:"elasticsearch"`
|
||||||
UILocalPath string `config:"ui_path"`
|
UI UIConfig `config:"ui"`
|
||||||
UILocalEnabled bool `config:"ui_local"`
|
Network config.NetworkConfig `config:"network"`
|
||||||
UIVFSEnabled bool `config:"ui_vfs"`
|
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"
|
||||||
}
|
}
|
||||||
|
|
18
main.go
18
main.go
|
@ -3,9 +3,11 @@ package main
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
_ "expvar"
|
_ "expvar"
|
||||||
|
"fmt"
|
||||||
"infini.sh/framework"
|
"infini.sh/framework"
|
||||||
"infini.sh/framework/core/elastic"
|
"infini.sh/framework/core/elastic"
|
||||||
"infini.sh/framework/core/env"
|
"infini.sh/framework/core/env"
|
||||||
|
"infini.sh/framework/core/global"
|
||||||
"infini.sh/framework/core/module"
|
"infini.sh/framework/core/module"
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
"infini.sh/framework/modules"
|
"infini.sh/framework/modules"
|
||||||
|
@ -50,12 +52,14 @@ func main() {
|
||||||
|
|
||||||
appConfig = &config.AppConfig{
|
appConfig = &config.AppConfig{
|
||||||
Elasticsearch: "default",
|
Elasticsearch: "default",
|
||||||
UILocalPath: ".public",
|
UI: config.UIConfig{
|
||||||
UIVFSEnabled: true,
|
LocalPath: ".public",
|
||||||
UILocalEnabled: true,
|
VFSEnabled: true,
|
||||||
|
LocalEnabled: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ok, err := env.ParseConfig("search-center", appConfig)
|
ok, err := env.ParseConfig("web", appConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -74,6 +78,12 @@ func main() {
|
||||||
// global.Env().SystemConfig.APIConfig.CrossDomain.AllowedOrigins=
|
// global.Env().SystemConfig.APIConfig.CrossDomain.AllowedOrigins=
|
||||||
// append(global.Env().SystemConfig.APIConfig.CrossDomain.AllowedOrigins,uiConfig.NetworkConfig.GetBindingAddr())
|
// 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
|
//start each module, with enabled provider
|
||||||
module.Start()
|
module.Start()
|
||||||
|
|
18
ui.go
18
ui.go
|
@ -2,7 +2,10 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"infini.sh/framework/core/global"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"src/github.com/segmentio/encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
public "infini.sh/search-center/.public"
|
public "infini.sh/search-center/.public"
|
||||||
|
|
||||||
|
@ -22,12 +25,25 @@ type UI struct {
|
||||||
|
|
||||||
func (h UI) InitUI() {
|
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()))
|
ui.HandleUI("/", vfs.FileServer(vfs.VFS()))
|
||||||
|
|
||||||
uiapi.Init(h.Config)
|
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) {
|
ui.HandleUIFunc("/api/", func(w http.ResponseWriter, req *http.Request) {
|
||||||
log.Warn("api: ", req.URL, " not implemented")
|
log.Warn("api: ", req.URL, " not implemented")
|
||||||
request, err := h.GetRawBody(req)
|
request, err := h.GetRawBody(req)
|
||||||
|
|
|
@ -50,7 +50,7 @@ export default {
|
||||||
define: {
|
define: {
|
||||||
APP_TYPE: process.env.APP_TYPE || '',
|
APP_TYPE: process.env.APP_TYPE || '',
|
||||||
ENV: process.env.NODE_ENV,
|
ENV: process.env.NODE_ENV,
|
||||||
API_ENDPOINT: 'http://localhost:2900',
|
API_ENDPOINT: process.env.API_ENDPOINT || '',
|
||||||
},
|
},
|
||||||
// 路由配置
|
// 路由配置
|
||||||
routes: pageRoutes,
|
routes: pageRoutes,
|
||||||
|
@ -125,7 +125,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
copy:[
|
copy:[
|
||||||
'./src/assets/favicon.ico'
|
'./src/assets/favicon.ico',
|
||||||
],
|
],
|
||||||
history: 'hash',
|
history: 'hash',
|
||||||
// exportStatic: {
|
// exportStatic: {
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
|
@ -185,7 +185,7 @@ export default class GlobalHeaderRight extends PureComponent {
|
||||||
bottomLeft: false,
|
bottomLeft: false,
|
||||||
topLeft: false,
|
topLeft: false,
|
||||||
}}> */}
|
}}> */}
|
||||||
<ConsoleUI selectedCluster={this.props.selectedCluster}
|
{this.props.clusterList.length > 0 && <ConsoleUI selectedCluster={this.props.selectedCluster}
|
||||||
clusterList={this.props.clusterList}
|
clusterList={this.props.clusterList}
|
||||||
visible={false}
|
visible={false}
|
||||||
minimize={true}
|
minimize={true}
|
||||||
|
@ -196,8 +196,7 @@ export default class GlobalHeaderRight extends PureComponent {
|
||||||
}}
|
}}
|
||||||
clusterStatus={this.props.clusterStatus}
|
clusterStatus={this.props.clusterStatus}
|
||||||
resizeable={true}
|
resizeable={true}
|
||||||
/>
|
/>}
|
||||||
{/* </Resizable> */}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -40,9 +40,6 @@ export default class GlobalHeader extends PureComponent {
|
||||||
};
|
};
|
||||||
render() {
|
render() {
|
||||||
const { collapsed, isMobile, logo, clusterVisible, clusterList, selectedCluster } = this.props;
|
const { collapsed, isMobile, logo, clusterVisible, clusterList, selectedCluster } = this.props;
|
||||||
if(clusterList.length == 0){
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.header}>
|
<div className={styles.header}>
|
||||||
{isMobile && (
|
{isMobile && (
|
||||||
|
@ -55,7 +52,8 @@ export default class GlobalHeader extends PureComponent {
|
||||||
type={collapsed ? 'menu-unfold' : 'menu-fold'}
|
type={collapsed ? 'menu-unfold' : 'menu-fold'}
|
||||||
onClick={this.toggle}
|
onClick={this.toggle}
|
||||||
/>
|
/>
|
||||||
<DropdownSelect defaultValue={selectedCluster}
|
|
||||||
|
{clusterList.length > 0 && <DropdownSelect defaultValue={selectedCluster}
|
||||||
clusterStatus={this.props.clusterStatus}
|
clusterStatus={this.props.clusterStatus}
|
||||||
value={selectedCluster}
|
value={selectedCluster}
|
||||||
labelField="name"
|
labelField="name"
|
||||||
|
@ -89,6 +87,7 @@ export default class GlobalHeader extends PureComponent {
|
||||||
}}
|
}}
|
||||||
size={56}
|
size={56}
|
||||||
data={clusterList}/>
|
data={clusterList}/>
|
||||||
|
}
|
||||||
<RightContent {...this.props} />
|
<RightContent {...this.props} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -87,7 +87,7 @@ const ConsoleWrapper = ({
|
||||||
|
|
||||||
</Tabs.TabPane>
|
</Tabs.TabPane>
|
||||||
<Tabs.TabPane tab="Headers" key="headers">
|
<Tabs.TabPane tab="Headers" key="headers">
|
||||||
<Tabs>
|
<Tabs animated={false}>
|
||||||
<Tabs.TabPane tab="Request" key="1">
|
<Tabs.TabPane tab="Request" key="1">
|
||||||
<EuiCodeBlock language="text" isCopyable paddingSize="s">
|
<EuiCodeBlock language="text" isCopyable paddingSize="s">
|
||||||
{lastDatum?.request.header}
|
{lastDatum?.request.header}
|
||||||
|
|
|
@ -139,10 +139,14 @@ export const ConsoleUI = ({selectedCluster,
|
||||||
return cm;
|
return cm;
|
||||||
}, [clusterList, clusterStatus])
|
}, [clusterList, clusterStatus])
|
||||||
const initialDefaultState = ()=>{
|
const initialDefaultState = ()=>{
|
||||||
const defaultActiveKey = `${selectedCluster.id}:${new Date().valueOf()}`;
|
let defaultCluster = selectedCluster;
|
||||||
const defaultState = selectedCluster? {
|
if(!defaultCluster.id){
|
||||||
|
defaultCluster = clusterList[0] ;
|
||||||
|
}
|
||||||
|
const defaultActiveKey = `${defaultCluster.id || ''}:${new Date().valueOf()}`;
|
||||||
|
const defaultState = defaultCluster? {
|
||||||
panes:[{
|
panes:[{
|
||||||
key: defaultActiveKey, cluster_id: selectedCluster.id, title: selectedCluster.name
|
key: defaultActiveKey, cluster_id: defaultCluster.id, title: defaultCluster.name
|
||||||
}],
|
}],
|
||||||
activeKey: defaultActiveKey,
|
activeKey: defaultActiveKey,
|
||||||
}: {panes:[],activeKey:''};
|
}: {panes:[],activeKey:''};
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import {useState, useRef, useEffect} from 'react';
|
import {useState, useRef, useEffect} from 'react';
|
||||||
import './console_tab_title.scss';
|
import './console_tab_title.scss';
|
||||||
import ElasticSvg from '@/assets/elasticsearch.svg';
|
import ElasticImg from '@/assets/elasticsearch.ico';
|
||||||
import {Icon} from 'antd';
|
import {Icon} from 'antd';
|
||||||
|
|
||||||
const ElasticIcon = () => (
|
const ElasticIcon = () => (
|
||||||
<img height="14px" width="14px" src={ElasticSvg} />
|
<img height="14px" width="14px" src={ElasticImg} />
|
||||||
);
|
);
|
||||||
|
|
||||||
interface TabTitleProps {
|
interface TabTitleProps {
|
||||||
|
|
|
@ -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){
|
export function buildQueryArgs(params){
|
||||||
let argsStr = '';
|
let argsStr = '';
|
||||||
for(let key in params){
|
for(let key in params){
|
||||||
|
@ -14,4 +43,4 @@ export function buildQueryArgs(params){
|
||||||
return argsStr;
|
return argsStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ESPrefix = (API_ENDPOINT || '') + '/elasticsearch';
|
export const ESPrefix = (apiEndpoint || '') + '/elasticsearch';
|
Loading…
Reference in New Issue