Skip to content

Commit ec6cf65

Browse files
authored
fix: check websites root path only when websites are defined (#853)
1 parent 3f0c727 commit ec6cf65

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

pkg/project/project.go

+29-26
Original file line numberDiff line numberDiff line change
@@ -854,37 +854,40 @@ func fromProjectConfiguration(projectConfig *ProjectConfiguration, localConfig *
854854
})
855855
}
856856

857-
// check for duplicate paths in websites and error
858-
siteDuplicates := lo.FindDuplicatesBy(websites, func(website Website) string {
859-
return website.path
860-
})
861-
862-
// check that there is a root website
863-
_, found := lo.Find(websites, func(website Website) bool {
864-
return website.path == "/"
865-
})
866-
if !found {
867-
return nil, fmt.Errorf("no root website found, please add a website with path /")
868-
}
869-
870-
// ensure there /api path is not used
871-
_, found = lo.Find(websites, func(website Website) bool {
872-
return strings.TrimSuffix(website.path, "/") == "/api"
873-
})
874-
if found {
875-
return nil, fmt.Errorf("path /api is reserved for API rewrites to APIs, please use a different path")
876-
}
857+
// website validation
858+
if len(websites) > 0 {
859+
if !slices.Contains(projectConfig.Preview, preview.Feature_Websites) {
860+
return nil, fmt.Errorf("project contains websites, but the project does not have the 'websites' preview feature enabled. Please add websites to the preview field of your nitric.yaml file to enable this feature")
861+
}
877862

878-
if len(siteDuplicates) > 0 {
879-
duplicatePaths := lo.Map(siteDuplicates, func(website Website, i int) string {
863+
// check for duplicate paths in websites and error
864+
siteDuplicates := lo.FindDuplicatesBy(websites, func(website Website) string {
880865
return website.path
881866
})
882867

883-
return nil, fmt.Errorf("duplicate website paths found: %s", strings.Join(duplicatePaths, ", "))
884-
}
868+
if len(siteDuplicates) > 0 {
869+
duplicatePaths := lo.Map(siteDuplicates, func(website Website, i int) string {
870+
return website.path
871+
})
885872

886-
if len(websites) > 0 && !slices.Contains(projectConfig.Preview, preview.Feature_Websites) {
887-
return nil, fmt.Errorf("project contains websites, but the project does not have the 'websites' preview feature enabled. Please add websites to the preview field of your nitric.yaml file to enable this feature")
873+
return nil, fmt.Errorf("duplicate website paths found: %s", strings.Join(duplicatePaths, ", "))
874+
}
875+
876+
// check that there is a root website
877+
_, found := lo.Find(websites, func(website Website) bool {
878+
return website.path == "/"
879+
})
880+
if !found {
881+
return nil, fmt.Errorf("no root website found, please add a website with path /")
882+
}
883+
884+
// ensure there /api path is not used
885+
_, found = lo.Find(websites, func(website Website) bool {
886+
return strings.TrimSuffix(website.path, "/") == "/api"
887+
})
888+
if found {
889+
return nil, fmt.Errorf("path /api is reserved for API rewrites to APIs, please use a different path")
890+
}
888891
}
889892

890893
// create an empty local configuration if none is provided

0 commit comments

Comments
 (0)