Use base url to generate template links/redirects
This commit is contained in:
@ -3,8 +3,10 @@ package route
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/wpetit/goweb-oidc/internal/config"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/middleware/container"
|
||||
"gitlab.com/wpetit/goweb/service"
|
||||
"gitlab.com/wpetit/goweb/service/template"
|
||||
"gitlab.com/wpetit/goweb/template/html"
|
||||
)
|
||||
@ -14,11 +16,22 @@ func extendTemplateData(w http.ResponseWriter, r *http.Request, data template.Da
|
||||
data, err := template.Extend(data,
|
||||
html.WithFlashes(w, r, ctn),
|
||||
template.WithBuildInfo(w, r, ctn),
|
||||
withBaseURL(w, r, ctn),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "could not extend template data"))
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
func withBaseURL(w http.ResponseWriter, r *http.Request, ctn *service.Container) template.DataExtFunc {
|
||||
return func(data template.Data) (template.Data, error) {
|
||||
conf, err := config.From(ctn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
data["BaseURL"] = conf.HTTP.PublicBaseURL
|
||||
return data, nil
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
oidc "forge.cadoles.com/wpetit/goweb-oidc"
|
||||
"forge.cadoles.com/wpetit/goweb-oidc/internal/config"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/middleware/container"
|
||||
"gitlab.com/wpetit/goweb/service/template"
|
||||
@ -12,11 +13,12 @@ import (
|
||||
func serveHomePage(w http.ResponseWriter, r *http.Request) {
|
||||
ctn := container.Must(r.Context())
|
||||
tmpl := template.Must(ctn)
|
||||
conf := config.Must(ctn)
|
||||
|
||||
idToken, _ := oidc.IDToken(w, r)
|
||||
|
||||
if idToken != nil {
|
||||
http.Redirect(w, r, "/profile", http.StatusSeeOther)
|
||||
http.Redirect(w, r, conf.HTTP.PublicBaseURL+"/profile", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
oidc "forge.cadoles.com/wpetit/goweb-oidc"
|
||||
"forge.cadoles.com/wpetit/goweb-oidc/internal/config"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/logger"
|
||||
"gitlab.com/wpetit/goweb/middleware/container"
|
||||
@ -27,7 +28,10 @@ func handleLoginCallback(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
ctn := container.Must(ctx)
|
||||
conf := config.Must(ctn)
|
||||
|
||||
logger.Info(ctx, "user logged in", logger.F("sub", idToken.Subject))
|
||||
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
http.Redirect(w, r, conf.HTTP.PublicBaseURL+"/", http.StatusSeeOther)
|
||||
}
|
||||
|
Reference in New Issue
Block a user