diff --git a/CHANGELOG.md b/CHANGELOG.md index e1d4552..4fef0a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,26 +1,12 @@ # Changelog -## v0.1.0 (2019/04/21) - -* Add Killgrave logo -* Add CircleCI integration -* Convert headers into canonical mime type -* Run server with imposter configuration -* Processing and parsing imposters file -* Initial version +## v0.3.2 (2019/05/08) -## v0.2.0 (2019/04/24) - -* Create an official docker image for the application -* Update README.md with how to use the application with docker -* Allow write headers for the response +* Fix CORS add AccessControl allowing methods and headers -## v0.2.1 (2019/04/25) +## v0.3.1 (2019/05/07) -* Allow imposter's matching by request schema -* Dynamic responses based on regex endpoint or request schema -* Calculate files directory(body and schema) based on imposters path -* Update REAMDE.md with resolved features and new future features +* Allow CORS requests ## v0.3.0 (2019/04/28) @@ -31,6 +17,24 @@ * Allow organize your imposters with structured folders (using new extension `.imp.json`) * Allow write multiple imposters by file -## v0.3.1 (2019/05/07) +## v0.2.1 (2019/04/25) -* Allow CORS requests +* Allow imposter's matching by request schema +* Dynamic responses based on regex endpoint or request schema +* Calculate files directory(body and schema) based on imposters path +* Update REAMDE.md with resolved features and new future features + +## v0.2.0 (2019/04/24) + +* Create an official docker image for the application +* Update README.md with how to use the application with docker +* Allow write headers for the response + +## v0.1.0 (2019/04/21) + +* Add Killgrave logo +* Add CircleCI integration +* Convert headers into canonical mime type +* Run server with imposter configuration +* Processing and parsing imposters file +* Initial version \ No newline at end of file diff --git a/cmd/killgrave/main.go b/cmd/killgrave/main.go index a0e9fc9..fda1b09 100644 --- a/cmd/killgrave/main.go +++ b/cmd/killgrave/main.go @@ -37,5 +37,5 @@ func main() { httpAddr := fmt.Sprintf("%s:%d", *host, *port) log.Printf("The fake server is on tap now: http://%s:%d\n", *host, *port) - log.Fatal(http.ListenAndServe(httpAddr, handlers.CORS()(r))) + log.Fatal(http.ListenAndServe(httpAddr, handlers.CORS(s.AccessControl()...)(r))) } diff --git a/internal/server.go b/internal/server.go index c69c38f..50c7089 100644 --- a/internal/server.go +++ b/internal/server.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" + "github.com/gorilla/handlers" "github.com/gorilla/mux" "github.com/pkg/errors" ) @@ -25,6 +26,13 @@ func NewServer(p string, r *mux.Router) *Server { } } +// AccessControl Return options to initialize the mock server with default access control +func (s *Server) AccessControl() (h []handlers.CORSOption) { + h = append(h, handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS", "DELETE", "PATCH", "TRACE", "CONNECT"})) + h = append(h, handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "*"})) + return +} + // Build read all the files on the impostersPath and add different // handlers for each imposter func (s *Server) Build() error { diff --git a/internal/server_test.go b/internal/server_test.go index 8a6f82d..2c8a84a 100644 --- a/internal/server_test.go +++ b/internal/server_test.go @@ -36,3 +36,12 @@ func TestRunServer(t *testing.T) { }) } } + +func TestAccessControl(t *testing.T) { + s := NewServer("test/testdata/imposters", mux.NewRouter()) + h := s.AccessControl() + + if len(h) <= 0 { + t.Fatal("Expected any CORS options and got empty") + } +}