diff --git a/satellite/path/paths.go b/satellite/path/paths.go index acbb999..917e32e 100644 --- a/satellite/path/paths.go +++ b/satellite/path/paths.go @@ -82,6 +82,9 @@ func (paths *Paths) Match(uri string) (*Path, bool) { for _, v := range paths.list { g := glob.MustCompile(v.Path, '/') if g.Match(uri) { + if v.HostedFile != "" { + return v, true + } if _, err := os.Stat(path.Join(paths.base, v.Path)); err != nil { v.HostedFile = v.Path } else { diff --git a/satellite/path/paths_test.go b/satellite/path/paths_test.go index 60b2841..821a62a 100644 --- a/satellite/path/paths_test.go +++ b/satellite/path/paths_test.go @@ -123,6 +123,41 @@ func TestNew_one(t *testing.T) { } } +func TestNew_different_hosted(t *testing.T) { + tmpdir, err := NewTempDir() + if err != nil { + t.Error(err) + } + defer tmpdir.Close() + tmpdir.CreatePathList(`- path: /index.html + hosted_file: abc`) + tmpdir.CreateFile("abc", Sentinal) + + paths, err := NewDefaultTest(tmpdir.Path) + if err != nil { + t.Error(err) + } + + req := httptest.NewRequest("GET", "/index.html", nil) + w := httptest.NewRecorder() + didMatch, err := paths.MatchAndServe(w, req) + if err != nil { + t.Error(err) + } + + if !didMatch { + t.Fail() + } + + data, err := ioutil.ReadAll(w.Result().Body) + if err != nil { + t.Fail() + } + if string(data) != Sentinal { + t.Fail() + } +} + func TestNew_proxy(t *testing.T) { tmpdir, err := NewTempDir() if err != nil {