More work on getting grafana pro to work in sub url
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/torkelo/grafana-pro/pkg/bus"
|
||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||
m "github.com/torkelo/grafana-pro/pkg/models"
|
||||
"github.com/torkelo/grafana-pro/pkg/setting"
|
||||
)
|
||||
|
||||
func getFrontendSettings(c *middleware.Context) (map[string]interface{}, error) {
|
||||
@@ -28,7 +29,7 @@ func getFrontendSettings(c *middleware.Context) (map[string]interface{}, error)
|
||||
url := ds.Url
|
||||
|
||||
if ds.Access == m.DS_ACCESS_PROXY {
|
||||
url = "/api/datasources/proxy/" + strconv.FormatInt(ds.Id, 10)
|
||||
url = setting.AppSubUrl + "/api/datasources/proxy/" + strconv.FormatInt(ds.Id, 10)
|
||||
}
|
||||
|
||||
var dsMap = map[string]interface{}{
|
||||
@@ -56,12 +57,12 @@ func getFrontendSettings(c *middleware.Context) (map[string]interface{}, error)
|
||||
// add grafana backend data source
|
||||
datasources["grafana"] = map[string]interface{}{
|
||||
"type": "grafana",
|
||||
"url": "",
|
||||
"grafanaDB": true,
|
||||
}
|
||||
|
||||
jsonObj := map[string]interface{}{
|
||||
"datasources": datasources,
|
||||
"appSubUrl": setting.AppSubUrl,
|
||||
}
|
||||
|
||||
return jsonObj, nil
|
||||
|
||||
+29
-20
@@ -80,39 +80,49 @@ func getWorkDir() string {
|
||||
return p
|
||||
}
|
||||
|
||||
func findConfigFile() string {
|
||||
func findConfigFiles() []string {
|
||||
WorkDir = getWorkDir()
|
||||
ConfRootPath = path.Join(WorkDir, "conf")
|
||||
filenames := make([]string, 0)
|
||||
|
||||
configFile := path.Join(ConfRootPath, "grafana.ini")
|
||||
//log.Info("Looking for config file: %v", configFile)
|
||||
if com.IsFile(configFile) {
|
||||
return configFile
|
||||
}
|
||||
configFile = path.Join(ConfRootPath, "grafana.dev.ini")
|
||||
//log.Info("Looking for config file: %v", configFile)
|
||||
if com.IsFile(configFile) {
|
||||
return configFile
|
||||
}
|
||||
configFile = path.Join(ConfRootPath, "grafana.example.ini")
|
||||
//log.Info("Looking for config file: %v", configFile)
|
||||
if com.IsFile(configFile) {
|
||||
return configFile
|
||||
filenames = append(filenames, configFile)
|
||||
}
|
||||
|
||||
log.Fatal(3, "Could not find any config file")
|
||||
return ""
|
||||
configFile = path.Join(ConfRootPath, "grafana.dev.ini")
|
||||
if com.IsFile(configFile) {
|
||||
filenames = append(filenames, configFile)
|
||||
}
|
||||
|
||||
configFile = path.Join(ConfRootPath, "grafana.custom.ini")
|
||||
if com.IsFile(configFile) {
|
||||
filenames = append(filenames, configFile)
|
||||
}
|
||||
|
||||
if len(filenames) == 0 {
|
||||
log.Fatal(3, "Could not find any config file")
|
||||
}
|
||||
|
||||
return filenames
|
||||
}
|
||||
|
||||
func NewConfigContext() {
|
||||
configFile := findConfigFile()
|
||||
configFiles := findConfigFiles()
|
||||
|
||||
log.Info("Loading config file: %v", configFile)
|
||||
log.Info("Loading config files: %v", configFiles)
|
||||
var err error
|
||||
|
||||
Cfg, err = goconfig.LoadConfigFile(configFile)
|
||||
Cfg, err = goconfig.LoadConfigFile(configFiles[0])
|
||||
if err != nil {
|
||||
log.Fatal(4, "Fail to parse %v, error: %v", configFile, err)
|
||||
log.Fatal(4, "Fail to parse config file, error: %v", err)
|
||||
}
|
||||
|
||||
if len(configFiles) > 1 {
|
||||
err = Cfg.AppendFiles(configFiles[1:]...)
|
||||
if err != nil {
|
||||
log.Fatal(4, "Fail to parse config file, error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
AppName = Cfg.MustValue("", "app_name", "Grafana")
|
||||
@@ -128,7 +138,6 @@ func NewConfigContext() {
|
||||
}
|
||||
|
||||
AppSubUrl = strings.TrimSuffix(url.Path, "/")
|
||||
log.Info("AppSubUrl: %v", AppSubUrl)
|
||||
|
||||
Protocol = HTTP
|
||||
if Cfg.MustValue("server", "protocol") == "https" {
|
||||
|
||||
Reference in New Issue
Block a user