Try to fix subdomains
Signed-off-by: Arzumify <jliwin98@danwin1210.de>
This commit is contained in:
parent
1d445cb61b
commit
c4dae7ac03
1
go.mod
1
go.mod
|
@ -8,6 +8,7 @@ require (
|
|||
git.ailur.dev/ailur/pow v1.0.0
|
||||
github.com/cespare/xxhash/v2 v2.3.0
|
||||
github.com/go-chi/chi/v5 v5.1.0
|
||||
github.com/go-chi/hostrouter v0.2.0
|
||||
github.com/go-playground/validator/v10 v10.22.1
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1
|
||||
github.com/google/uuid v1.6.0
|
||||
|
|
3
go.sum
3
go.sum
|
@ -12,8 +12,11 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
|
|||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4=
|
||||
github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4=
|
||||
github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs=
|
||||
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
|
||||
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
||||
github.com/go-chi/hostrouter v0.2.0 h1:GwC7TZz8+SlJN/tV/aeJgx4F+mI5+sp+5H1PelQUjHM=
|
||||
github.com/go-chi/hostrouter v0.2.0/go.mod h1:pJ49vWVmtsKRKZivQx0YMYv4h0aX+Gcn6V23Np9Wf1s=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||
|
|
13
main.go
13
main.go
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"errors"
|
||||
library "git.ailur.dev/ailur/fg-library"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
@ -20,6 +19,7 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/hostrouter"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/google/uuid"
|
||||
|
||||
|
@ -478,6 +478,7 @@ func main() {
|
|||
// Create the router
|
||||
router := chi.NewRouter()
|
||||
router.Use(logger)
|
||||
hostRouter := hostrouter.New()
|
||||
|
||||
var globalOutbox = make(chan library.InterServiceMessage)
|
||||
|
||||
|
@ -564,20 +565,16 @@ func main() {
|
|||
lock.Unlock()
|
||||
|
||||
// Check if they want a subdomain
|
||||
var finalRouter *chi.Mux
|
||||
finalRouter := chi.NewRouter()
|
||||
serviceConfig, ok := config.Services[strings.ToLower(serviceInformation.Name)]
|
||||
if !ok {
|
||||
slog.Error("Service configuration not found for service: ", serviceInformation.Name)
|
||||
os.Exit(1)
|
||||
}
|
||||
if serviceConfig.(map[string]interface{})["subdomain"] != nil {
|
||||
subdomainRouter := chi.NewRouter()
|
||||
router.Use(middleware.RouteHeaders().
|
||||
Route("Host", config.Services[strings.ToLower(serviceInformation.Name)].(map[string]interface{})["subdomain"].(string), middleware.New(subdomainRouter)).
|
||||
Handler)
|
||||
finalRouter = subdomainRouter
|
||||
hostRouter.Map(serviceConfig.(map[string]interface{})["subdomain"].(string), finalRouter)
|
||||
} else {
|
||||
finalRouter = router
|
||||
hostRouter.Map("", finalRouter)
|
||||
}
|
||||
|
||||
slog.Info("Activating service " + serviceInformation.Name + " with ID " + serviceInformation.ServiceID.String())
|
||||
|
|
Loading…
Reference in New Issue