Skip to content
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

Can't reproduce FileServer chi/example - 404 page not found #2

Open
sinetoami opened this issue Oct 18, 2019 · 0 comments
Open

Can't reproduce FileServer chi/example - 404 page not found #2

sinetoami opened this issue Oct 18, 2019 · 0 comments

Comments

@sinetoami
Copy link

sinetoami commented Oct 18, 2019

I've tried a tons of solutions to get work a file server on my project. Even in my test the standard example does not work properly. What I ever receive is 404 page not found. Here's a piece of my code, including server and test:

## ./server.go
func newRouter() *chi.Mux {
	r := chi.NewRouter()
	r.Mount("/api/v3", routes())
	r.Handle("/*", http.FileServer(unindexed.Dir("../assets/")))
	return r
}

func routes() http.Handler {
	r := chi.NewRouter()
	r.Get("/", home)
	return r
}

## ./server_test.go
func TestAssetsFileServer(t *testing.T) {
	r := newRouter()
	mockServer := httptest.NewServer(r)

	resp, err := http.Get(mockServer.URL + "/api/v3/assets")
	if err != nil {
		t.Fatal(err)
	}

	if resp.StatusCode != http.StatusOK {
		t.Errorf("Status should be 200, got %d", resp.StatusCode)
	}

	contentType := resp.Header.Get("Content-Type")
	expectedContentType := "text/html; charset=utf-8"
	if expectedContentType != contentType {
		t.Errorf("Wrong content type, expected %s, got %s", expectedContentType, contentType)
	}
}

The version of my Golang is 1.13, working on Linux.
So, what am I doing wrong?
Thanks!

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

No branches or pull requests

1 participant