diff --git a/http/server.go b/http/server.go index 788cb7e..7fa5cde 100644 --- a/http/server.go +++ b/http/server.go @@ -2,7 +2,8 @@ package http import ( "net/http" - "fmt" + "strings" + "os" ) func NewServer(port string) (error) { @@ -15,13 +16,21 @@ func NewServer(port string) (error) { } func server_setup(server *http.ServeMux) { - server.HandleFunc("/", test) + server.HandleFunc("/", serve_main_page) + server.HandleFunc("/live/", serve_live_playlist) } -func test(w http.ResponseWriter, r *http.Request) { - test_buf := make([]byte, 32) - copy(test_buf, "test\ntest") - if _, err := w.Write(test_buf); err != nil { - fmt.Println(err) +func serve_live_playlist(w http.ResponseWriter, r *http.Request) { + stream_id := strings.TrimPrefix(r.URL.Path, "/live/") + base_dir, _ := os.UserHomeDir() + stream_playlist_path := base_dir + "/live/" + stream_id + "/stream.m3u8" + if _, err := os.Stat(stream_playlist_path); err != nil { + http.NotFound(w, r) + } else { + http.ServeFile(w, r, stream_playlist_path) } } + +func serve_main_page(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, "static/index.html") +} diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..e69f963 --- /dev/null +++ b/static/index.html @@ -0,0 +1,9 @@ + + + + Test + + +

Test

+ +