Added custom headers option
This commit is contained in:
+44
-10
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
@@ -17,17 +18,25 @@ type ForwardRule struct {
|
||||
Compiled *regexp.Regexp
|
||||
}
|
||||
|
||||
type CustomHeader struct {
|
||||
Source string `yaml:"source"`
|
||||
Regex bool `yaml:"regex"`
|
||||
Headers map[string]string `yaml:"headers"`
|
||||
Compiled *regexp.Regexp
|
||||
}
|
||||
|
||||
type SiteConfig struct {
|
||||
Name string `yaml:"name"`
|
||||
Repo string `yaml:"repo"`
|
||||
Owner string `yaml:"owner"`
|
||||
Branch string `yaml:"branch"`
|
||||
Domain string `yaml:"domain"`
|
||||
Enabled bool `yaml:"enabled"`
|
||||
SPA bool `yaml:"spa"`
|
||||
NotFoundFile string `yaml:"not_found_file"`
|
||||
DeployToken string `yaml:"deploy_token"`
|
||||
ForwardRules []ForwardRule `yaml:"forward_rules"`
|
||||
Name string `yaml:"name"`
|
||||
Repo string `yaml:"repo"`
|
||||
Owner string `yaml:"owner"`
|
||||
Branch string `yaml:"branch"`
|
||||
Domain string `yaml:"domain"`
|
||||
Enabled bool `yaml:"enabled"`
|
||||
SPA bool `yaml:"spa"`
|
||||
NotFoundFile string `yaml:"not_found_file"`
|
||||
DeployToken string `yaml:"deploy_token"`
|
||||
ForwardRules []ForwardRule `yaml:"forward_rules"`
|
||||
CustomHeaders []CustomHeader `yaml:"custom_headers"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
@@ -84,6 +93,31 @@ func validateConfig(config *Config) error {
|
||||
config.Sites[i].ForwardRules[j].Compiled = re
|
||||
}
|
||||
}
|
||||
for k, header := range site.CustomHeaders {
|
||||
if header.Source == "" {
|
||||
return &Error{Field: fmt.Sprintf("sites[%d].custom_headers[%d].source", i, k), Message: "Source is required"}
|
||||
}
|
||||
if len(header.Headers) == 0 {
|
||||
return &Error{Field: fmt.Sprintf("sites[%d].custom_headers[%d].headers", i, k), Message: "At least one header is required"}
|
||||
}
|
||||
if header.Regex {
|
||||
re, err := regexp.Compile(header.Source)
|
||||
if err != nil {
|
||||
return &Error{
|
||||
Field: fmt.Sprintf("sites[%d].custom_headers[%d].source", i, k),
|
||||
Message: "Invalid regex: " + err.Error(),
|
||||
}
|
||||
}
|
||||
config.Sites[i].CustomHeaders[k].Compiled = re
|
||||
} else {
|
||||
if _, err := path.Match(header.Source, ""); err != nil {
|
||||
return &Error{
|
||||
Field: fmt.Sprintf("sites[%d].custom_headers[%d].source", i, k),
|
||||
Message: "Invalid glob pattern: " + err.Error(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user