Stylesheet not loaded because of MIME-type in go

Viewed 33

I'm new to GO and I want to make a back-end server with it. I've done a function that removes the .html from the URL, here's the code:

http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

    // hack, if requested url is / then point towards /index
    if r.URL.Path == "/" {
        r.URL.Path = "/index"
    }

    requestedPath := strings.TrimLeft(filepath.Clean(r.URL.Path), "/")
    filename := fmt.Sprintf("%s/%s.html", "./web-files", requestedPath)
    http.ServeFile(w, r, filename)
}))

http.ListenAndServe(":8080", nil)

At first, the code was OK, but went I tried to create a styles.css file and link it to the HTML file I got the following error at the console:

Refused to apply style from 'http://localhost:8080/styles.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

0 Answers
Related