Skip to content

Default is to serve the wrong content type. #4

@michael-lloyd-morris

Description

@michael-lloyd-morris

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions