Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions pkg/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,37 +854,40 @@ func fromProjectConfiguration(projectConfig *ProjectConfiguration, localConfig *
})
}

// check for duplicate paths in websites and error
siteDuplicates := lo.FindDuplicatesBy(websites, func(website Website) string {
return website.path
})

// check that there is a root website
_, found := lo.Find(websites, func(website Website) bool {
return website.path == "/"
})
if !found {
return nil, fmt.Errorf("no root website found, please add a website with path /")
}

// ensure there /api path is not used
_, found = lo.Find(websites, func(website Website) bool {
return strings.TrimSuffix(website.path, "/") == "/api"
})
if found {
return nil, fmt.Errorf("path /api is reserved for API rewrites to APIs, please use a different path")
}
// website validation
if len(websites) > 0 {
if !slices.Contains(projectConfig.Preview, preview.Feature_Websites) {
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")
}

if len(siteDuplicates) > 0 {
duplicatePaths := lo.Map(siteDuplicates, func(website Website, i int) string {
// check for duplicate paths in websites and error
siteDuplicates := lo.FindDuplicatesBy(websites, func(website Website) string {
return website.path
})

return nil, fmt.Errorf("duplicate website paths found: %s", strings.Join(duplicatePaths, ", "))
}
if len(siteDuplicates) > 0 {
duplicatePaths := lo.Map(siteDuplicates, func(website Website, i int) string {
return website.path
})

if len(websites) > 0 && !slices.Contains(projectConfig.Preview, preview.Feature_Websites) {
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")
return nil, fmt.Errorf("duplicate website paths found: %s", strings.Join(duplicatePaths, ", "))
}

// check that there is a root website
_, found := lo.Find(websites, func(website Website) bool {
return website.path == "/"
})
if !found {
return nil, fmt.Errorf("no root website found, please add a website with path /")
}

// ensure there /api path is not used
_, found = lo.Find(websites, func(website Website) bool {
return strings.TrimSuffix(website.path, "/") == "/api"
})
if found {
return nil, fmt.Errorf("path /api is reserved for API rewrites to APIs, please use a different path")
}
}

// create an empty local configuration if none is provided
Expand Down