Files
go2rtc/cmd/api/static.go
2022-08-19 16:56:44 +03:00

26 lines
433 B
Go

package api
import (
"github.com/AlexxIT/go2rtc/www"
"net/http"
)
func initStatic(staticDir string) {
var root http.FileSystem
if staticDir != "" {
root = http.Dir(staticDir)
} else {
root = http.FS(www.Static)
}
fileServer := http.FileServer(root)
HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if basePath != "" {
r.URL.Path = r.URL.Path[len(basePath):]
}
fileServer.ServeHTTP(w, r)
})
}