mirror of
https://github.com/pagefaultgames/rogueserver.git
synced 2025-04-04 20:17:15 +08:00
Re-add debug mode
This commit is contained in:
parent
2f8c2d3f07
commit
6ae46dfd77
@ -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
|
||||||
|
if !*debug {
|
||||||
err = http.Serve(listener, mux)
|
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)
|
||||||
}
|
}
|
||||||
@ -69,3 +75,18 @@ 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…
x
Reference in New Issue
Block a user