diff --git a/internal/config/config.go b/internal/config/config.go index f0c4448..fe01450 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "net/url" "os" "path/filepath" "reflect" @@ -92,6 +93,10 @@ func InitConfig(configPath string) error { return err } + if err = checks(c); err != nil { + return err + } + C = c return nil @@ -222,3 +227,15 @@ func loadConfigFromEnv(c *config) error { return nil } + +func checks(c *config) error { + if _, err := url.Parse(c.ExternalUrl); err != nil { + return err + } + + if _, err := url.Parse(c.GiteaUrl); err != nil { + return err + } + + return nil +} diff --git a/internal/web/admin.go b/internal/web/admin.go index 9111f74..25d2c10 100644 --- a/internal/web/admin.go +++ b/internal/web/admin.go @@ -189,7 +189,6 @@ func adminConfig(ctx echo.Context) error { setData(ctx, "title", "Configuration") setData(ctx, "htmlTitle", "Configuration - Admin panel") setData(ctx, "adminHeaderPage", "config") - setData(ctx, "c", config.C) return html(ctx, "admin_config.html") } diff --git a/internal/web/run.go b/internal/web/run.go index edee67f..0d92733 100644 --- a/internal/web/run.go +++ b/internal/web/run.go @@ -85,7 +85,7 @@ var fm = template.FuncMap{ if dev { return "http://localhost:16157/" + jsfile } - return "/" + manifestEntries[jsfile].File + return config.C.ExternalUrl + "/" + manifestEntries[jsfile].File }, "defaultAvatar": defaultAvatar, } @@ -256,6 +256,8 @@ func dataInit(next echo.HandlerFunc) echo.HandlerFunc { return errorRes(500, "Cannot read settings from database", err) } + setData(ctx, "c", config.C) + setData(ctx, "githubOauth", config.C.GithubClientKey != "" && config.C.GithubSecret != "") setData(ctx, "giteaOauth", config.C.GiteaClientKey != "" && config.C.GiteaSecret != "") @@ -377,5 +379,5 @@ func defaultAvatar() string { if dev { return "http://localhost:16157/default.png" } - return "/" + manifestEntries["default.png"].File + return config.C.ExternalUrl + "/" + manifestEntries["default.png"].File } diff --git a/internal/web/util.go b/internal/web/util.go index 0facd5c..8f6fbd2 100644 --- a/internal/web/util.go +++ b/internal/web/util.go @@ -10,6 +10,7 @@ import ( "github.com/go-playground/validator/v10" "github.com/gorilla/sessions" "github.com/labstack/echo/v4" + "github.com/thomiceli/opengist/internal/config" "github.com/thomiceli/opengist/internal/models" "golang.org/x/crypto/argon2" "html/template" @@ -44,7 +45,7 @@ func htmlWithCode(ctx echo.Context, code int, template string) error { } func redirect(ctx echo.Context, location string) error { - return ctx.Redirect(302, location) + return ctx.Redirect(302, config.C.ExternalUrl+location) } func plainText(ctx echo.Context, code int, message string) error { diff --git a/templates/base/admin_header.html b/templates/base/admin_header.html index cecf911..1613c57 100644 --- a/templates/base/admin_header.html +++ b/templates/base/admin_header.html @@ -9,13 +9,13 @@
Forked from {{ .gist.Forked.User.Username }}/{{ .gist.Forked.Title }}
+Forked from {{ .gist.Forked.User.Username }}/{{ .gist.Forked.Title }}
{{ end }}Last active Unlisted {{ end }} @@ -110,13 +110,13 @@
{{ if .gist.Private }} •