Class: Pact::Consumer::CorsOriginHeaderMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/consumer/mock_service/cors_origin_header_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, cors_enabled) ⇒ CorsOriginHeaderMiddleware

Returns a new instance of CorsOriginHeaderMiddleware.



5
6
7
8
# File 'lib/pact/consumer/mock_service/cors_origin_header_middleware.rb', line 5

def initialize app, cors_enabled
  @app = app
  @cors_enabled = cors_enabled
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/pact/consumer/mock_service/cors_origin_header_middleware.rb', line 10

def call env
  response = @app.call env
  if env['HTTP_X_PACT_MOCK_SERVICE'] || @cors_enabled
    add_cors_header env, response
  else
    response
  end
end

#shutdownObject



19
20
21
# File 'lib/pact/consumer/mock_service/cors_origin_header_middleware.rb', line 19

def shutdown
  @app.shutdown
end