From f25a415a9ed8ac99ef12822c6edae61a2b678247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sun, 4 Jan 2015 21:03:40 +0100 Subject: [PATCH] Work on making grafana work in sub url --- grafana | 2 +- pkg/api/api.go | 9 ++++++--- pkg/middleware/auth.go | 3 ++- pkg/setting/setting.go | 2 ++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/grafana b/grafana index 5a3d3f5098c..5feed2344ab 160000 --- a/grafana +++ b/grafana @@ -1 +1 @@ -Subproject commit 5a3d3f5098c3dfe42d4fbe63f3c43d0d1a154d8a +Subproject commit 5feed2344ab8a5eb65ffeda9ccae8b768e9b8764 diff --git a/pkg/api/api.go b/pkg/api/api.go index 42a04796574..d8489f493d3 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -4,6 +4,7 @@ import ( "github.com/Unknwon/macaron" "github.com/torkelo/grafana-pro/pkg/api/dtos" "github.com/torkelo/grafana-pro/pkg/middleware" + "github.com/torkelo/grafana-pro/pkg/setting" ) func Register(m *macaron.Macaron) { @@ -36,7 +37,7 @@ func Register(m *macaron.Macaron) { m.Any("/api/datasources/proxy/:id/*", auth, ProxyDataSourceRequest) // user register - m.Get("/register/*_", Index) + m.Get("/register", Index) m.Post("/api/account", CreateAccount) // dashboards @@ -57,8 +58,10 @@ func Index(ctx *middleware.Context) { return } - ctx.Data["user"] = dtos.NewCurrentUser(ctx.UserAccount) - ctx.Data["settings"] = settings + ctx.Data["User"] = dtos.NewCurrentUser(ctx.UserAccount) + ctx.Data["Settings"] = settings + ctx.Data["AppUrl"] = setting.AppUrl + ctx.Data["AppSubUrl"] = setting.AppSubUrl ctx.HTML(200, "index") } diff --git a/pkg/middleware/auth.go b/pkg/middleware/auth.go index b1ce5b50a91..6de623b30cb 100644 --- a/pkg/middleware/auth.go +++ b/pkg/middleware/auth.go @@ -9,6 +9,7 @@ import ( "github.com/torkelo/grafana-pro/pkg/bus" m "github.com/torkelo/grafana-pro/pkg/models" + "github.com/torkelo/grafana-pro/pkg/setting" ) func authGetRequestAccountId(c *Context, sess session.Store) (int64, error) { @@ -29,7 +30,7 @@ func authGetRequestAccountId(c *Context, sess session.Store) (int64, error) { } func authDenied(c *Context) { - c.Redirect("/login") + c.Redirect(setting.AppSubUrl + "/login") } func Auth() macaron.Handler { diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index 9ef53b9a92b..05f4e4c707e 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -126,7 +126,9 @@ func NewConfigContext() { if err != nil { log.Fatal(4, "Invalid root_url(%s): %s", AppUrl, err) } + AppSubUrl = strings.TrimSuffix(url.Path, "/") + log.Info("AppSubUrl: %v", AppSubUrl) Protocol = HTTP if Cfg.MustValue("server", "protocol") == "https" {