Simplify the setup of bundled assets (#436)

1. Move the generated file to handlers - it better belongs there
2. Ensure that all file serves are also handled by the asset store

Co-authored-by: Marcos Lilljedahl <marcosnils@gmail.com>
This commit is contained in:
Paul Jolly
2020-10-20 04:45:42 +01:00
committed by GitHub
parent 958feeb51d
commit ef0ac9be48
6 changed files with 32 additions and 20 deletions

View File

@@ -3,7 +3,6 @@ package handlers
import (
"log"
"net/http"
"os"
"path/filepath"
"github.com/gorilla/mux"
@@ -34,12 +33,17 @@ func Home(w http.ResponseWriter, r *http.Request) {
return
}
index := filepath.Join("./www", playground.AssetsDir, "/index.html")
if _, err := os.Stat(index); os.IsNotExist(err) {
index = "./www/default/index.html"
index, err := Asset(filepath.Join(playground.AssetsDir, "/index.html"))
if err != nil {
index, err = Asset("default/index.html")
}
http.ServeFile(w, r, index)
if err != nil {
w.WriteHeader(http.StatusFound)
return
}
w.Write(index)
}
func Landing(rw http.ResponseWriter, req *http.Request) {