mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 04:35:40 +00:00
refactor: remove root url
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"tinyauth/internal/auth"
|
||||
"tinyauth/internal/hooks"
|
||||
"tinyauth/internal/types"
|
||||
"tinyauth/internal/utils"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-contrib/sessions/cookie"
|
||||
@@ -33,8 +34,13 @@ func Run(config types.Config, users types.UserList) {
|
||||
fileServer := http.FileServer(http.FS(dist))
|
||||
store := cookie.NewStore([]byte(config.Secret))
|
||||
|
||||
domain := strings.Split(config.RootURL, "://")[1]
|
||||
domain, domainErr := utils.GetRootURL(config.AppURL)
|
||||
|
||||
if domainErr != nil {
|
||||
log.Fatal().Err(domainErr).Msg("Failed to get domain")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
store.Options(sessions.Options{
|
||||
Domain: fmt.Sprintf(".%s", domain),
|
||||
Path: "/",
|
||||
|
||||
@@ -22,7 +22,6 @@ type Config struct {
|
||||
Port int `validate:"number" mapstructure:"port"`
|
||||
Address string `mapstructure:"address, ip4_addr"`
|
||||
Secret string `validate:"required,len=32" mapstructure:"secret"`
|
||||
RootURL string `validate:"required,url" mapstructure:"root-url"`
|
||||
AppURL string `validate:"required,url" mapstructure:"app-url"`
|
||||
Users string `validate:"required" mapstructure:"users"`
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"strings"
|
||||
"tinyauth/internal/types"
|
||||
)
|
||||
@@ -26,4 +27,18 @@ func CreateUsersList(users string) (types.UserList, error) {
|
||||
}
|
||||
|
||||
return userList, nil
|
||||
}
|
||||
|
||||
func GetRootURL(urlSrc string) (string, error) {
|
||||
urlParsed, parseErr := url.Parse(urlSrc)
|
||||
|
||||
if parseErr != nil {
|
||||
return "", parseErr
|
||||
}
|
||||
|
||||
urlSplitted := strings.Split(urlParsed.Host, ".")
|
||||
|
||||
urlFinal := urlSplitted[len(urlSplitted)-2] + "." + urlSplitted[len(urlSplitted)-1]
|
||||
|
||||
return urlFinal, nil
|
||||
}
|
||||
Reference in New Issue
Block a user