#How to serve static files for specific handler

3 messages · Page 1 of 1 (latest)

open oriole
#

Let's say we have 3 endpoints. Each endpoint loads a different HTML layout and also each has its own CSS/JS files.
I was able to load static files But this always loads for all endpoints.

What I want is to load a specific static file for a specific endpoint.

func main() {
  http.HandleFunc("/about", aboutHandler)
  http.HandleFunc("/product", productHandler)
  
  // *** This loads on all endpoints
  fs:=http.FileServer(http.Dir("./static/")
  http.Handle("/static/", http.StripPrefix("/static/",fs))
}

func aboutHandler(w http.ResponseWritter, r *http.Request) {
  
  // *** I've tried to load it here, but shows the content of my CSS/js files instead of about.html

  tpl:=template.Must(template.ParseFile("./about.html")
  w.Heaer().Add("content-type", "text/html")
  tpl.Execute(w, nil)
}
median flame
#

have you checked what requests are being made by your browser?

open oriole