Skip to content

Commit

Permalink
feat: check for duplicate domains across apps
Browse files Browse the repository at this point in the history
  • Loading branch information
jozefcipa committed May 5, 2024
1 parent 2db75d8 commit 8b61941
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"os"
"slices"

"github.com/jozefcipa/novus/internal/brew"
"github.com/jozefcipa/novus/internal/config"
Expand Down Expand Up @@ -61,6 +62,31 @@ var serveCmd = &cobra.Command{
}
}

// TODO: refactor this into a function and move to some module
// Check if there are duplicate domains across apps
type AppDomain struct {
App string
Domain string
}
allDomains := []AppDomain{}
for appName, appConfig := range novus.GetState().Apps {
for _, route := range appConfig.Routes {
allDomains = append(allDomains, AppDomain{App: appName, Domain: route.Domain})
}
}
for _, route := range addedRoutes {
if idx := slices.IndexFunc(allDomains, func(appDomain AppDomain) bool { return appDomain.Domain == route.Domain }); idx != -1 {
usedDomainAppName := allDomains[idx].App
logger.Errorf("Domain %s is already defined by app \"%s\"", route.Domain, usedDomainAppName)
logger.Hintf("Use a different domain name or temporarily stop \"%[1]s\" by running `novus stop %[1]s`", usedDomainAppName)
os.Exit(1)
}
allDomains = append(allDomains, AppDomain{App: conf.AppName, Domain: route.Domain})
}

// fmt.Print("all domains", allDomains)
// os.Exit(0)

// Configure SSL
mkcert.Configure(conf)
domainCerts, hasNewCerts := ssl_manager.EnsureSSLCertificates(conf)
Expand Down

0 comments on commit 8b61941

Please sign in to comment.