John Eliud
John Eliud

Reputation: 11

Stylesheet properties not reflecting on the webpage due to MIME type

I am working on a project that runs a web server on a specified port written in Golang. The styling properies of the page don't reflect and the following error is logged on the browser console. Refused to apply style from 'http://localhost:9000/static/style.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

My index.html file is in a folder named templates while the style.css file in a folder named static. This is how I specified the link relation of the stylesheet in the HTML file. <link rel="stylesheet" href="/static/style.css" />

The main.go file inside a folder named cmd is where I serve the static folder as illustrated below.

func main() {
    http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))

    http.HandleFunc("/", handlers.ServeIndex)

    port := ":9000"

    log.Printf("Server started at http://localhost%v", port)
    http.ListenAndServe(port, nil)
}

Based on the provided information, what could be the issue leading to the problem?

I have tried clearing the browser's cache hoping the issue would be solved but that didn't solve the problem. Project file structure

Upvotes: 1

Views: 46

Answers (0)

Related Questions