2
votes

My Pact mock server is listening in different port from my tests and my pact mock server is running with following configuration:

const provider = pact({
consumer: 'myconsumer',
provider: 'myprovider',
port: 8989,
cors: true,
log: path.resolve(process.cwd(), 'logs', 'pact.log'),
dir: path.resolve(process.cwd(), 'pacts'),
logLevel: 'DEBUG',
spec: 1
});

I request the above mock server using 'axios' and the request is matched with one of the interaction i have configured on the provider (as per pact.log). But response always throws error with CORS.

My pact log has following information: Received OPTIONS request for mock service administration endpoint POST /interactions. Returning CORS headers: {"Access-Control-Allow-Origin":"null","Access-Control-Allow-Headers":"x-pact-mock-service","Access-Control-Allow-Methods":"DELETE, POST, GET, HEAD, PUT, TRACE, CONNECT, PATCH"}.

why is Access-Control-Allow-Origin is null instead of '*'. ?

How can i disable CORS security completely with tests as the final resorts when i use webpack, npm and mocha based tests.?

1

1 Answers

2
votes

That CORS flag is slightly misleading. If your app uses CORS then you will still need to tell Pact that it should expect a request for OPTIONS as per the cors standard. This is part of the contract and you can't just expect your server to work, so it should be part of your tests.

See https://github.com/pact-foundation/pact-js/issues/58 for background.