Add external url to HTML links & redirects (#75)

This commit is contained in:
Thomas Miceli
2023-07-03 16:31:12 +02:00
committed by GitHub
parent 7515e82d34
commit 038d81df2d
18 changed files with 86 additions and 67 deletions

View File

@ -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")
}

View File

@ -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
}

View File

@ -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 {