dndex/server/static.go

19 lines
419 B
Go

package server
import (
"local/dndex/config"
"local/simpleserve/simpleserve"
"net/http"
"os"
"path"
)
func (rest *REST) static(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(path.Join(config.New().StaticRoot, r.URL.Path)); os.IsNotExist(err) {
r.URL.Path = "/"
}
simpleserve.SetContentTypeIfMedia(w, r)
server := http.FileServer(http.Dir(config.New().StaticRoot))
server.ServeHTTP(w, r)
}