Working boilerplate.
This commit is contained in:
@@ -1,8 +1,36 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func spaHandler() http.HandlerFunc {
|
||||
fs := getUIAssets()
|
||||
fileServer := http.FileServer(http.FS(fs))
|
||||
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/" {
|
||||
fileServer.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
f, err := fs.Open(strings.TrimPrefix(path.Clean(r.URL.Path), "/"))
|
||||
if err == nil {
|
||||
defer f.Close()
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
r.URL.Path = "/"
|
||||
}
|
||||
fileServer.ServeHTTP(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
frontend := getUIAssets()
|
||||
fmt.Println(frontend)
|
||||
|
||||
log.Println("Starting glancr on port 8080")
|
||||
http.HandleFunc("/", spaHandler())
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user