Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS OPTIONS headers not working when using a remote server #721

Closed
jsanta opened this issue Jul 19, 2017 · 4 comments
Closed

CORS OPTIONS headers not working when using a remote server #721

jsanta opened this issue Jul 19, 2017 · 4 comments

Comments

@jsanta
Copy link

jsanta commented Jul 19, 2017

Hi.
I'm currently using wiremock on a remote server outside my network.
Using the current configuration for the OPTIONS method like:

{
  "priority":10,
  "request": {
    "method": "OPTIONS",
    "urlPattern": ".*"
  },
  "response": {
    "status": 200,
    "headers": {
        "Content-Type": "application/json",
        "Access-Control-Allow-Origin" : "*",
        "Access-Control-Allow-Methods" : "*",
        "Access-Control-Allow-Headers": "Accept, Content-Type, Content-Encoding, Server, Transfer-Encoding, X-Requested-With, X-Authorization",
        "X-Content-Type-Options" : "nosniff",
        "x-frame-options" : "DENY",
        "x-xss-protection" : "1; mode=block"
    }
  }
}

works perfectly if I'm connecting from the same network.
After uploading the same mapping files to a remote server, I'm getting this error message:

XMLHttpRequest cannot load http://my_remote_server:port/api/endpoint. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://my_local_ip:local_port' is therefore not allowed access. The response had HTTP status code 404.

I currently solved it by duplicating my request mappings, changing the method to OPTIONS and deleting the response leaving only a status 200.

Is there any way to get CORS working without this dirty workarounds?

@jsanta jsanta changed the title CORS headers not working when using a remote server CORS OPTIONS headers not working when using a remote server Jul 19, 2017
@tomakehurst
Copy link
Member

As per the readme please post questions to the mailing list.

Also suggest posting a bit more detail about how you're calling the endpoint and how you loaded the mappings into the remote server.

@jsanta
Copy link
Author

jsanta commented Jul 19, 2017

OK not making any more questions.

I uploaded all my wiremock folder (including __files, mappings and a custom response folder for static response files) to the server.
Running the server using java -jar /opt/wiremock/wiremock-standalone-2.6.0.jar --port 8090 --verbose
No firewall issues detected as the request gets to the server, but goes directly to the error endpoint:

{
  "priority":10,
  "request": {
    "method": "ANY",
    "urlPattern": ".*"
  },
  "response": {
    "status": 404,
    "jsonBody": {"status":"Error","message":"Endpoint not found"},
    "headers": {
      "Content-Type": "application/json"
    }
  }
}

The calls are being done through a Ionic app, using Angular. I'm debugging the app through the browser. No issues either in the browser.

Please point me out if there's any other information you require to attend the issue (ignore the question about dirty workarounds).
Thanks!

@ashishgodani
Copy link

Even I am facing the same issue

@binque
Copy link

binque commented Apr 25, 2018

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants