Hello everybody.
This is a simple web application witch uses embedded fs for storing css and js files
package main
import (
"embed"
"io/fs"
"net/http"
)
//go:embed static/*
var StaticFiles embed.FS
type StaticPath struct {
StaticP embed.FS
}
func (s StaticPath) ServeHTTP(w http.ResponseWriter, req *http.Request) {
publicFS, _ := fs.Sub(s.StaticP, "static")
http.FileServer(http.FS(publicFS)).ServeHTTP(w, req)
}
func NewRouter() *http.ServeMux {
r := http.NewServeMux()
r.Handle("/", StaticPath{
StaticP: StaticFiles,
})
return r
}
func main() {
srv := &http.Server{
Addr: "localhost:3000",
Handler: NewRouter(),
}
_ = srv.ListenAndServe()
}
directory struccture:
βββ go.mod
βββ go.sum
βββ main.go
βββ static
βββ index.html
βββ style.css
2 directories, 5 files
apache 2 configuration is: (cat /etc/apache2/conf-enabled/app1.conf)
<VirtualHost *:80>
ProxyPass /app1 http://localhost:3000/
ProxyPassReverse /app1 http://localhost:3000/
</VirtualHost>
Html page served fine but css and js files in static folder not.
I do not have a clue where the problem is. Could somebody help me?