0

I'm trying to fetch the list of official images from docker hub using v2 api. If I try to do curl or use postman, I get the response correctly, but when I try to fetch the list using angularjs service, I get the following error

XMLHttpRequest cannot load https://hub.docker.com/v2/repositories/library/?page=8&page_size=15. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://run.plnkr.co' is therefore not allowed access.

Can someone suggest solution for this. How can I enable cors for this?

user2427829
  • 128
  • 1
  • 7

3 Answers3

1

CORS could be enabled on the server side, and this is not your case. What you could do is :

1) use a proxy, for instance NGNIX, and make Sure that all request Made to localhost/whatever are redirected to hub.docker.com . This way you can "cheat" Cross-origin block

2) if you need a temporary and dirty solution you could more simply install chrome/safari plugins to bypass CORS security check

Andrea Di Lisio
  • 465
  • 5
  • 17
0

There is only one way to bypass CORS is send request through a cors proxy like http://crossorigin.me

It's an opensource project and you can build your own proxy server by download the full source code from here: https://github.com/technoboy10/crossorigin.me

Daniel Pham
  • 146
  • 2
  • 5
0

Reason behind the issue :

As per my understanding you are doing an AJAX call to a different domain than your page is on. So, the browser is blocking it for security reasons as it usually allows a request in the same origin.A tutorial about how to achieve that is using CORS.

When you are using curl or postman they are not restricted by this policy. Quoted from Cross-Origin XMLHttpRequest:

Regular web pages can use the XMLHttpRequest object to send and receive data from remote servers, but they're limited by the same origin policy. Extensions aren't so limited. An extension can talk to remote servers outside of its origin, as long as it first requests cross-origin permissions.

Debug Diva
  • 26,058
  • 13
  • 70
  • 123