Adds static www content to binary

This commit is contained in:
Alexey Khit
2022-08-19 16:55:50 +03:00
parent 3e1f4a0110
commit f879663f55
5 changed files with 34 additions and 23 deletions
+25
View File
@@ -0,0 +1,25 @@
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)
})
}