mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-09-27 04:36:12 +08:00
28 lines
501 B
Go
28 lines
501 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/AlexxIT/go2rtc/www"
|
|
)
|
|
|
|
func initStatic(staticDir string) {
|
|
var root http.FileSystem
|
|
if staticDir != "" {
|
|
log.Info().Str("dir", staticDir).Msg("[api] serve static")
|
|
root = http.Dir(staticDir)
|
|
} else {
|
|
root = http.FS(www.Static)
|
|
}
|
|
|
|
base := len(basePath)
|
|
fileServer := http.FileServer(root)
|
|
|
|
HandleFunc("", func(w http.ResponseWriter, r *http.Request) {
|
|
if base > 0 {
|
|
r.URL.Path = r.URL.Path[base:]
|
|
}
|
|
fileServer.ServeHTTP(w, r)
|
|
})
|
|
}
|