Skip to content

Fix Static files route not working #1654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed

Fix Static files route not working #1654

wants to merge 4 commits into from

Conversation

pwli0755
Copy link
Contributor

fix 404 error when using Static files route Echo.Static()

related issue

@codecov
Copy link

codecov bot commented Oct 15, 2020

Codecov Report

Merging #1654 into master will decrease coverage by 1.11%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1654      +/-   ##
==========================================
- Coverage   85.28%   84.17%   -1.12%     
==========================================
  Files          28       28              
  Lines        2216     1902     -314     
==========================================
- Hits         1890     1601     -289     
+ Misses        212      189      -23     
+ Partials      114      112       -2     
Impacted Files Coverage Δ
echo.go 85.55% <100.00%> (-0.38%) ⬇️
middleware/proxy.go 60.97% <0.00%> (-5.37%) ⬇️
middleware/method_override.go 80.95% <0.00%> (-3.67%) ⬇️
middleware/redirect.go 85.00% <0.00%> (-3.24%) ⬇️
context.go 86.59% <0.00%> (-3.13%) ⬇️
middleware/basic_auth.go 65.62% <0.00%> (-2.95%) ⬇️
middleware/util.go 88.88% <0.00%> (-1.74%) ⬇️
response.go 85.18% <0.00%> (-1.66%) ⬇️
middleware/cors.go 77.94% <0.00%> (-1.52%) ⬇️
middleware/key_auth.go 66.66% <0.00%> (-1.13%) ⬇️
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 151ed6b...f1495e1. Read the comment docs.

@pwli0755 pwli0755 changed the title Fix Static files route not working #1569 Fix Static files route not working Oct 16, 2020
@@ -496,6 +496,7 @@ func (common) static(prefix, root string, get func(string, HandlerFunc, ...Middl
}
return c.File(name)
}
get(prefix, h)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Maybe you can add a new unit test, to avoid future regressions

func TestEchoStaticRedirectIndex(t *testing.T) {
	assert := assert.New(t)
	e := New()

	// HandlerFunc
	e.Static("/static", "_fixture")

	errCh := make(chan error)

	go func() {
		errCh <- e.Start("127.0.0.1:1323")
	}()

	time.Sleep(200 * time.Millisecond)

	if resp, err := http.Get("http://127.0.0.1:1323/static"); err == nil {
		defer resp.Body.Close()
		assert.Equal(http.StatusOK, resp.StatusCode)

		if body, err := ioutil.ReadAll(resp.Body); err == nil {
			assert.Equal(true, strings.HasPrefix(string(body), "<!doctype html>"))
		} else {
			assert.Fail(err.Error())
		}

	} else {
		assert.Fail(err.Error())
	}

	if err := e.Close(); err != nil {
		t.Fatal(err)
	}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I'll fix the Directory Redirect test case and add a TestEchoStaticRedirectIndex func for strengthening.

Copy link
Contributor

@pafuent pafuent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert on Codecov, but when I updated my PRs with the latest changes on master, it pass. Maybe it was in a weird state when you created your PR in the first place, and the comparison with the coverage on master is not quite correct. My suggestion is to update this PR with the latest master changes.

@pwli0755
Copy link
Contributor Author

pwli0755 commented Nov 6, 2020

closing,move to #1671

@pwli0755 pwli0755 closed this Nov 6, 2020
@pwli0755
Copy link
Contributor Author

pwli0755 commented Nov 6, 2020

I'm not an expert on Codecov, but when I updated my PRs with the latest changes on master, it pass. Maybe it was in a weird state when you created your PR in the first place, and the comparison with the coverage on master is not quite correct. My suggestion is to update this PR with the latest master changes.

just opened another PR, pls have a check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants