Re-add debug mode

pull/4/head
maru 7 months ago
parent 2f8c2d3f07
commit 6ae46dfd77
No known key found for this signature in database
GPG Key ID: 37689350E9CD0F0D

@ -14,6 +14,8 @@ import (
func main() { func main() {
// flag stuff // flag stuff
debug := flag.Bool("debug", false, "use debug mode")
proto := flag.String("proto", "tcp", "protocol for api to use (tcp, unix)") proto := flag.String("proto", "tcp", "protocol for api to use (tcp, unix)")
addr := flag.String("addr", "0.0.0.0", "network address for api to listen on") addr := flag.String("addr", "0.0.0.0", "network address for api to listen on")
@ -47,7 +49,11 @@ func main() {
api.Init(mux) api.Init(mux)
// start web server // start web server
err = http.Serve(listener, mux) if !*debug {
err = http.Serve(listener, mux)
} else {
err = http.Serve(listener, debugHandler(mux))
}
if err != nil { if err != nil {
log.Fatalf("failed to create http server or server errored: %s", err) log.Fatalf("failed to create http server or server errored: %s", err)
} }
@ -68,4 +74,19 @@ func createListener(proto, addr string) (net.Listener, error) {
} }
return listener, nil return listener, nil
} }
func debugHandler(router *http.ServeMux) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Headers", "*")
w.Header().Set("Access-Control-Allow-Methods", "*")
w.Header().Set("Access-Control-Allow-Origin", "*")
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
router.ServeHTTP(w, r)
})
}

Loading…
Cancel
Save