diff --git a/src/server.go b/src/server.go index d1bf1ee..083d72d 100644 --- a/src/server.go +++ b/src/server.go @@ -14,7 +14,7 @@ type ServerCommand struct { Port int `short:"p" long:"port" description:"Port to listen on." default:"8080"` - Routes []string `short:"r" long:"route" description:"Route which is made up of a path, a response body, and a response status, all separated by the pipe '|' character. Repeat for additional routes." default:"/|testing 123|200"` + Routes []string `short:"r" long:"route" description:"Route which is made up of a path, a response body, and a response status, all separated by the pipe '|' character. Repeat for additional routes."` Cors bool `short:"c" long:"cors" description:"Enable Cross Origin Resource Sharing (CORS). Allows all requested methods and headers."` Headers []string `short:"H" long:"header" description:"A header to add to response in the form name:value. Use multiple times for multiple headers."` } @@ -51,6 +51,9 @@ } } fmt.Println() + } else { + // wildcard mode + http.HandleFunc("/", serverRequestHandler) } if err := http.ListenAndServe(":"+strconv.Itoa(opts.Port), nil); err != nil { @@ -67,6 +70,15 @@ body := bodies[path] code := statuses[path] + // are we in wildcard mode? + if code == 0 && len(statuses) == 0 { + if req.Method == http.MethodGet { + code = 200 + } else { + code = 204 + } + } + showRequest(req) // CORS preflight