You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
775 B
Go
42 lines
775 B
Go
2 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
mux := http.NewServeMux()
|
||
|
|
||
|
setupRoutes(mux)
|
||
|
|
||
|
server := http.Server{
|
||
|
Addr: ":4000",
|
||
|
Handler: mux,
|
||
|
}
|
||
|
|
||
|
log.Printf("Starting server on port 4000...")
|
||
|
log.Fatal(server.ListenAndServe())
|
||
|
}
|
||
|
|
||
|
func setupRoutes(mux *http.ServeMux) {
|
||
|
mux.HandleFunc("/api/status", func(w http.ResponseWriter, r *http.Request) {
|
||
|
if r.Method != http.MethodGet {
|
||
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
w.Header().Set("Content-Type", "application/json")
|
||
|
|
||
|
err := json.NewEncoder(w).Encode("ok")
|
||
|
if err != nil {
|
||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||
|
return
|
||
|
}
|
||
|
})
|
||
|
|
||
|
// Static Files
|
||
|
mux.Handle("/", http.FileServer(http.Dir("./dist/")))
|
||
|
}
|