change(backend): serve static file from /static and serve index.html for /
This commit is contained in:
parent
dc68e4a8d4
commit
85dff8deca
1 changed files with 8 additions and 14 deletions
22
main.go
22
main.go
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -10,19 +9,14 @@ var currentConfig config
|
||||||
|
|
||||||
func handleRequest(w http.ResponseWriter, r *http.Request) {
|
func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
path := r.URL.Path
|
path := r.URL.Path
|
||||||
switch r.Method {
|
if path == "/" {
|
||||||
case "GET":
|
http.ServeFile(w, r, "./static/index.html")
|
||||||
if path == "/" {
|
|
||||||
http.ServeFile(w, r, "./static/index.html")
|
|
||||||
|
|
||||||
} else if strings.HasPrefix(path, "/static/") {
|
} else if strings.HasPrefix(path, "/static/") {
|
||||||
fs := http.FileServer(http.Dir("./static"))
|
fs := http.FileServer(http.Dir("./static"))
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
}
|
|
||||||
case "POST":
|
|
||||||
fmt.Println("Post!")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,6 +28,6 @@ func main() {
|
||||||
|
|
||||||
err := http.ListenAndServe(listen, nil)
|
err := http.ListenAndServe(listen, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue