@@ -63,11 +63,21 @@ func traefikAnnotationsToApp(service Service) (*erconfig.Application, error) {
6363 }
6464
6565 frontend , err := func () (erconfig.Frontend , error ) {
66+ parsed , err := parseTraefikFrontendRule (frontendRule )
67+ if err != nil {
68+ return erconfig.Frontend {}, err
69+ }
70+
71+ opts := []erconfig.FrontendOpt {}
72+ if parsed .PathPrefix != "" {
73+ opts = append (opts , erconfig .PathPrefix (parsed .PathPrefix ))
74+ }
75+
6676 switch {
67- case strings . HasPrefix ( frontendRule , "Host:" ) :
68- return erconfig .SimpleHostnameFrontend (frontendRule [ len ( " Host:" ):] ), nil
69- case strings . HasPrefix ( frontendRule , "HostRegexp:" ) :
70- return erconfig .RegexpHostnameFrontend (frontendRule [ len ( " HostRegexp:" ):] ), nil
77+ case parsed . Host != "" :
78+ return erconfig .SimpleHostnameFrontend (parsed . Host , opts ... ), nil
79+ case parsed . HostRegexp != "" :
80+ return erconfig .RegexpHostnameFrontend (parsed . HostRegexp , opts ... ), nil
7181 default :
7282 return erconfig.Frontend {}, fmt .Errorf ("unsupported frontend rule: %s" , frontendRule )
7383 }
@@ -137,3 +147,33 @@ func traefikAnnotationsToApp(service Service) (*erconfig.Application, error) {
137147
138148 return & app , nil
139149}
150+
151+ type traefikFrontendRule struct {
152+ Host string `json:",omitempty"` // `Host:...` rule
153+ PathPrefix string `json:",omitempty"` // `PathPrefix:...` rule
154+ HostRegexp string `json:",omitempty"` // `HostRegexp:...` rule
155+ }
156+
157+ // https://doc.traefik.io/traefik/v1.7/user-guide/examples/#using-labels-in-docker-composeyml
158+ func parseTraefikFrontendRule (rule string ) (traefikFrontendRule , error ) {
159+ parsed := traefikFrontendRule {}
160+
161+ // `Host:example.com;PathPrefix:/admin/`
162+ // => `["Host:example.com", "PathPrefix:/admin/"]`
163+ subRules := strings .Split (rule , ";" )
164+
165+ for _ , subRule := range subRules {
166+ switch {
167+ case strings .HasPrefix (subRule , "Host:" ):
168+ parsed .Host = subRule [len ("Host:" ):]
169+ case strings .HasPrefix (subRule , "PathPrefix:" ):
170+ parsed .PathPrefix = subRule [len ("PathPrefix:" ):]
171+ case strings .HasPrefix (subRule , "HostRegexp:" ):
172+ parsed .HostRegexp = subRule [len ("HostRegexp:" ):]
173+ default :
174+ return parsed , fmt .Errorf ("unsupported rule: '%s'" , subRule )
175+ }
176+ }
177+
178+ return parsed , nil
179+ }
0 commit comments