added static files and moved templates to own dir

This commit is contained in:
BroodjeAap 2020-06-29 19:19:24 +00:00
parent 343d9c7cee
commit e1fcf85910
5 changed files with 9 additions and 3 deletions

View file

@ -3,6 +3,7 @@ package main
import ( import (
"log" "log"
"net/http" "net/http"
"path/filepath"
"text/template" "text/template"
) )
@ -12,7 +13,7 @@ type StreamURL struct {
} }
func index(w http.ResponseWriter, r *http.Request) { func index(w http.ResponseWriter, r *http.Request) {
indexTemplate, err := template.ParseFiles(("index.html")) indexTemplate, err := template.ParseFiles(filepath.Join("templates", "index.html"))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -27,7 +28,7 @@ func stream(w http.ResponseWriter, r *http.Request) {
streamURL := StreamURL{ streamURL := StreamURL{
URL: r.FormValue("URL"), URL: r.FormValue("URL"),
} }
streamTemplate, err := template.ParseFiles(("stream.html")) streamTemplate, err := template.ParseFiles(filepath.Join("templates", "stream.html"))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -37,6 +38,9 @@ func stream(w http.ResponseWriter, r *http.Request) {
} }
func main() { func main() {
staticFileServer := http.FileServer(http.Dir("./static"))
http.Handle("/static/", http.StripPrefix("/static/", staticFileServer))
http.HandleFunc("/", index) http.HandleFunc("/", index)
http.HandleFunc("/stream", stream) http.HandleFunc("/stream", stream)
log.Fatal(http.ListenAndServe(":8080", nil)) log.Fatal(http.ListenAndServe(":8080", nil))

1
static/js/stream.js Executable file
View file

@ -0,0 +1 @@
alert("test");

1
tmp/air_errors.log Normal file
View file

@ -0,0 +1 @@
exit status 2exit status 2exit status 2exit status 2