1
0
mirror of https://github.com/umputun/reproxy.git synced 2025-07-12 22:20:55 +02:00

flip order in docker proxy+static labels #55

we want proxy rule to have priority over assets rule
This commit is contained in:
Umputun
2021-04-23 04:05:14 -05:00
parent c590c3246d
commit efded2cf5e
2 changed files with 27 additions and 5 deletions

View File

@ -135,6 +135,12 @@ func (d *Docker) List() ([]discovery.URLMapper, error) {
mp := discovery.URLMapper{Server: strings.TrimSpace(srv), SrcMatch: *srcRegex, Dst: destURL,
PingURL: pingURL, ProviderID: discovery.PIDocker, MatchType: discovery.MTProxy}
// for assets we add the second proxy mapping only if explicitly requested
if assetsWebRoot != "" && explicit {
mp.MatchType = discovery.MTProxy
res = append(res, mp)
}
if assetsWebRoot != "" {
mp.MatchType = discovery.MTStatic
mp.AssetsWebRoot = assetsWebRoot
@ -142,11 +148,6 @@ func (d *Docker) List() ([]discovery.URLMapper, error) {
}
res = append(res, mp)
// for assets we add the second proxy mapping only if explicitly requested
if assetsWebRoot != "" && explicit {
mp.MatchType = discovery.MTProxy
res = append(res, mp)
}
}
}

View File

@ -114,6 +114,27 @@ func TestDocker_ListWithAutoAPI(t *testing.T) {
assert.Equal(t, "*", res[2].Server)
}
func TestDocker_ListPriority(t *testing.T) {
dclient := &DockerClientMock{
ListContainersFunc: func() ([]containerInfo, error) {
return []containerInfo{
{
Name: "c0", State: "running", IP: "127.0.0.2", Ports: []int{12348},
Labels: map[string]string{"reproxy.route": "^/whoami/(.*)", "reproxy.dest": "/$1",
"reproxy.server": "example.com", "reproxy.ping": "/ping", "reproxy.assets": "/:/assets/static1"},
},
}, nil
},
}
d := Docker{DockerClient: dclient}
res, err := d.List()
require.NoError(t, err)
require.Equal(t, 2, len(res))
assert.Equal(t, discovery.MTProxy, res[0].MatchType)
assert.Equal(t, discovery.MTStatic, res[1].MatchType)
}
func TestDocker_refresh(t *testing.T) {
containers := make(chan []containerInfo)