console and cors
This commit is contained in:
parent
b8e6c8a579
commit
dc4202ba3a
|
@ -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"`
|
||||
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"
|
||||
}
|
||||
|
|
18
main.go
18
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()
|
||||
|
|
18
ui.go
18
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)
|
||||
|
|
|
@ -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: {
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
|
@ -185,7 +185,7 @@ export default class GlobalHeaderRight extends PureComponent {
|
|||
bottomLeft: false,
|
||||
topLeft: false,
|
||||
}}> */}
|
||||
<ConsoleUI selectedCluster={this.props.selectedCluster}
|
||||
{this.props.clusterList.length > 0 && <ConsoleUI selectedCluster={this.props.selectedCluster}
|
||||
clusterList={this.props.clusterList}
|
||||
visible={false}
|
||||
minimize={true}
|
||||
|
@ -196,8 +196,7 @@ export default class GlobalHeaderRight extends PureComponent {
|
|||
}}
|
||||
clusterStatus={this.props.clusterStatus}
|
||||
resizeable={true}
|
||||
/>
|
||||
{/* </Resizable> */}
|
||||
/>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -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 (
|
||||
<div className={styles.header}>
|
||||
{isMobile && (
|
||||
|
@ -55,7 +52,8 @@ export default class GlobalHeader extends PureComponent {
|
|||
type={collapsed ? 'menu-unfold' : 'menu-fold'}
|
||||
onClick={this.toggle}
|
||||
/>
|
||||
<DropdownSelect defaultValue={selectedCluster}
|
||||
|
||||
{clusterList.length > 0 && <DropdownSelect defaultValue={selectedCluster}
|
||||
clusterStatus={this.props.clusterStatus}
|
||||
value={selectedCluster}
|
||||
labelField="name"
|
||||
|
@ -89,6 +87,7 @@ export default class GlobalHeader extends PureComponent {
|
|||
}}
|
||||
size={56}
|
||||
data={clusterList}/>
|
||||
}
|
||||
<RightContent {...this.props} />
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -87,7 +87,7 @@ const ConsoleWrapper = ({
|
|||
|
||||
</Tabs.TabPane>
|
||||
<Tabs.TabPane tab="Headers" key="headers">
|
||||
<Tabs>
|
||||
<Tabs animated={false}>
|
||||
<Tabs.TabPane tab="Request" key="1">
|
||||
<EuiCodeBlock language="text" isCopyable paddingSize="s">
|
||||
{lastDatum?.request.header}
|
||||
|
|
|
@ -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:''};
|
||||
|
|
|
@ -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 = () => (
|
||||
<img height="14px" width="14px" src={ElasticSvg} />
|
||||
<img height="14px" width="14px" src={ElasticImg} />
|
||||
);
|
||||
|
||||
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){
|
||||
let argsStr = '';
|
||||
for(let key in params){
|
||||
|
@ -14,4 +43,4 @@ export function buildQueryArgs(params){
|
|||
return argsStr;
|
||||
}
|
||||
|
||||
export const ESPrefix = (API_ENDPOINT || '') + '/elasticsearch';
|
||||
export const ESPrefix = (apiEndpoint || '') + '/elasticsearch';
|
Loading…
Reference in New Issue