lib/pact/consumer/mock_service/options.rb in pact-mock_service-0.2.3.pre.rc2 vs lib/pact/consumer/mock_service/options.rb in pact-mock_service-0.2.3

- old
+ new

@@ -19,23 +19,16 @@ def match? env is_options_request?(env) && (cors_enabled || is_administration_request?(env)) end def respond env - logger.info "Received OPTIONS request for #{env['HTTP_ACCESS_CONTROL_REQUEST_METHOD']} #{env['PATH_INFO']}. Returning CORS headers." - [200, - { - 'Access-Control-Allow-Origin' => '*', - 'Access-Control-Allow-Headers' => headers_from(env)["Access-Control-Request-Headers"], - 'Access-Control-Allow-Methods' => 'DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT' - }, - [] - ] - end - - # Access-Control-Domain does not work on OPTIONs requests. - def enable_cors? - false + cors_headers = { + 'Access-Control-Allow-Origin' => env.fetch('HTTP_ORIGIN','*'), + 'Access-Control-Allow-Headers' => headers_from(env)["Access-Control-Request-Headers"], + 'Access-Control-Allow-Methods' => 'DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT' + } + logger.info "Received OPTIONS request for mock service administration endpoint #{env['HTTP_ACCESS_CONTROL_REQUEST_METHOD']} #{env['PATH_INFO']}. Returning CORS headers: #{cors_headers.to_json}." + [200, cors_headers, []] end def is_options_request? env env['REQUEST_METHOD'] == 'OPTIONS' end