Giter Site home page Giter Site logo

Comments (7)

bethesque avatar bethesque commented on June 19, 2024

Your Http-Origin header appears to be empty:

[response[0], response[1].merge('Access-Control-Allow-Origin' => env.fetch('HTTP_ORIGIN','*')), response[2]]

from pact-mock_service.

bethesque avatar bethesque commented on June 19, 2024

Here's some documentation on using CORS with the mock service. https://github.com/pact-foundation/pact-mock_service/wiki/Using-the-mock-service-with-CORS

from pact-mock_service.

alagesann avatar alagesann commented on June 19, 2024

Why is http-origin header empty when pact mock service is created with cors enabled ( Please note pact mock service creation config above with cors: true). cors_origin_header_middleware adds the 'Access-Control-Allow-Origin with value of '*' when i create pact mock service with cors enabled. but thats not seems to work for me as i have cors enabled and Access-Control-Allow-Origin is still null.

from pact-mock_service.

bethesque avatar bethesque commented on June 19, 2024
def add_cors_header env, response
  [response[0], response[1].merge('Access-Control-Allow-Origin' => env.fetch('HTTP_ORIGIN','*')), response[2]]
end

env.fetch will return the second argument if the given key is not found. As env.fetch('HTTP_ORIGIN','*') is returning nil, it suggests that you have an Http-Origin header set with an empty value.

from pact-mock_service.

alagesann avatar alagesann commented on June 19, 2024

Thanks for clarifying it.

i am using mocha to fire my tests and for a react-action in testing, it logs the following request in pact.log:

I, [2017-07-17T11:34:55.421448 #15431] INFO -- : Received request GET /mydata?address=75001
D, [2017-07-17T11:34:55.421542 #15431] DEBUG -- : {
"path": "/mydata",
"query": "address=75001",
"method": "get",
"headers": {
"Accept": "application/json",
"Referer": "about:blank",
"User-Agent": "Node.js (darwin; U; rv:v7.10.0) AppleWebKit/537.36 (KHTML, like Gecko)",
"Accept-Language": "en",
"Origin": "null",
"Host": "localhost:8989",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Version": "HTTP/1.1"
}
}

Here "Origin": "null" is populated automatically and even though request matches with the interaction and generates the pact file but the response is not returned from mock server. How do i resolve the issue now?

from pact-mock_service.

alagesann avatar alagesann commented on June 19, 2024

My local nodejs was automatically populating the request header with origin null. Pact started working fine when i fixed it. Thanks for your time. @bethesque

from pact-mock_service.

bethesque avatar bethesque commented on June 19, 2024

No worries, glad you've fixed it.

from pact-mock_service.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.