-
Notifications
You must be signed in to change notification settings - Fork 9
/
ui.go
79 lines (67 loc) · 2.39 KB
/
ui.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (C) INFINI Labs & INFINI LIMITED.
//
// The INFINI Console is offered under the GNU Affero General Public License v3.0
// and as commercial software.
//
// For commercial licensing, contact us at:
// - Website: infinilabs.com
// - Email: [email protected]
//
// Open Source licensed under AGPL V3:
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"fmt"
public "infini.sh/console/.public"
"net/http"
log "github.com/cihub/seelog"
"infini.sh/console/config"
uiapi "infini.sh/console/plugin/api"
"infini.sh/framework/core/api"
"infini.sh/framework/core/util"
"infini.sh/framework/core/vfs"
)
type UI struct {
api.Handler
Config *config.AppConfig
}
func (h UI) InitUI() {
vfs.RegisterFS(public.StaticFS{StaticFolder: h.Config.UI.LocalPath, TrimLeftPath: h.Config.UI.LocalPath, CheckLocalFirst: h.Config.UI.LocalEnabled, SkipVFS: !h.Config.UI.VFSEnabled})
api.HandleUI("/", vfs.FileServer(vfs.VFS()))
uiapi.Init(h.Config)
//var apiEndpoint = h.Config.UI.APIEndpoint
//apiConfig := &global.Env().SystemConfig.APIConfig
//
//api.HandleUIFunc("/config", func(w http.ResponseWriter, req *http.Request){
// if(strings.TrimSpace(apiEndpoint) == ""){
// hostParts := strings.Split(req.RemoteIP, ":")
// apiEndpoint = fmt.Sprintf("%s//%s:%s", apiConfig.GetSchema(), hostParts[0], apiConfig.NetworkConfig.GetBindingPort())
// }
// buf, _ := json.Marshal(util.MapStr{
// "api_endpoint": apiEndpoint,
// })
// w.Write(buf)
//})
api.HandleUIFunc("/api/", func(w http.ResponseWriter, req *http.Request) {
log.Warn("api: ", req.URL, " not implemented")
request, err := h.GetRawBody(req)
if err != nil {
fmt.Println(err)
return
}
response := map[string]interface{}{}
response["request"] = string(request)
w.Write(util.MustToJSONBytes(request))
})
}