Ioana Adrian
Ioana Adrian

Reputation: 19

Golang css serve

I hope you don't find my question stupid, but I really couldn't find an answer.

I am trying to serve my style.css file, but it won't work.

This is the structure of the project: enter image description here

In the css file i have: "link href="style.css" rel="stylesheet" type="text/css"/"

In the mainn.go I am trying to serve the css file using this: router.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("/hpages"))))

Any help will be appreciated. Thanks!

Upvotes: 1

Views: 80

Answers (1)

0xCC
0xCC

Reputation: 69

/hpages is an absolute path. Maybe try ./hpages instead.

The following program, run on my local machine works:

package main

import (
  "log"
  "net/http"
)

func main() {
  router := http.NewServeMux()
  router.Handle("/css/", http.StripPrefix("/css/",
                http.FileServer(http.Dir("./hpages"))))
  log.Fatal(http.ListenAndServe(":5000", router))
}

Upvotes: 2

Related Questions