Bug fixes new functional
This commit is contained in:
parent
d3b60c5a45
commit
4094942a24
21
main.go
21
main.go
@ -6,7 +6,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -309,14 +308,22 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
staticContent, _ := fs.Sub(staticFS, ".")
|
indexHTML, _ := staticFS.ReadFile("index.html")
|
||||||
staticHandler := http.FileServer(http.FS(staticContent))
|
faviconICO, _ := staticFS.ReadFile("favicon.ico")
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path == "/" {
|
switch r.URL.Path {
|
||||||
r = r.Clone(r.Context())
|
case "/", "/index.html":
|
||||||
r.URL.Path = "/index.html"
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write(indexHTML)
|
||||||
|
case "/favicon.ico":
|
||||||
|
w.Header().Set("Content-Type", "image/x-icon")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write(faviconICO)
|
||||||
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
}
|
}
|
||||||
staticHandler.ServeHTTP(w, r)
|
|
||||||
})
|
})
|
||||||
http.HandleFunc("/api/messages", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/api/messages", func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user