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

Default is to serve the wrong content type. #4

Open
michael-lloyd-morris opened this issue Oct 26, 2021 · 0 comments
Open

Default is to serve the wrong content type. #4

michael-lloyd-morris opened this issue Oct 26, 2021 · 0 comments

Comments

@michael-lloyd-morris
Copy link

michael-lloyd-morris commented Oct 26, 2021

Given:

func newServer(rootDir string) *http.Server {
	fs := http.FileServer(http.Dir(rootDir))
	mux := http.NewServeMux()

	mux.Handle("/", fs)
	srv := &http.Server{
		Addr:    httpPort,
		Handler: mux,
	}

	return srv
}

That should set up a basic usable webserver for static files like, say, the ones generated by the Hugo project right? Wrong.

Js files - served as text/plain. CSS files - text/plain. HTML file, you guessed it, text/plain. While you can configure a browser to ignore this, it throws a wrench into testing.

This is a bug because it renders this library call unusable as far as I can tell.

Every similar library in ever other language I've used infers the content type from the extension by default.

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