I am trying to embed a static site (and SPA) into my Go code. The high level structure of my project is
.
├── web.go
└── spa/
└── index.html
My intent is to have http://localhost:8090/
serving index.html
.
The relevant code to do that is
//go:embed spa
var spa embed.FS
log.Info("starting api server")
r := mux.NewRouter()
r.Handle("/", http.FileServer(http.FS(spa)))
log.Fatal(http.ListenAndServe(":8090", r))
When accessing http://localhost:8090/
, I get
- a directory listing page with a single link
spa
- upon clicking on this link I get a
404 page not found
How should I set this up?
http://localhost:8090/spa/
ultimately reaches theindex.html
file and the URI ishttp://localhost:8090/spa/#/
(and the content is fully visible). Thanks a lot for that. I will read about how to redirect/
to/spa/
in order to have the root serving the SPA. – Prau