0

I want to show some Dockerhub image statistics on a website. To acomplish this, i tried making an GET Request to my dockerhub Repo, which when visited should get me a json file, that contains the data i need.

The GET request should go here: https://hub.docker.com/v2/repositories/freddy0/crafty-container/

Currently i got this working

function dockerPulls(image){
  var data = JSON.parse(image);
  return data.pull_count;
}

Which when called on a local .json file returns the pul count just fine

when i try to acess the json via the javascript file i made i get some errors, which i am seemingly not able to fix

This is my fetch code, which is simply copied from chrome dev tools > resource > copy as fetch

fetch("https://hub.docker.com/v2/repositories/freddy0/crafty-container/", {
  "headers": {
    "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
    "accept-language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
    "cache-control": "no-cache",
    "pragma": "no-cache",
    "sec-fetch-dest": "document",
    "sec-fetch-mode": "navigate",
    "sec-fetch-site": "none",
    "sec-fetch-user": "?1",
    "sec-gpc": "1",
    "upgrade-insecure-requests": "1"
  },
  "referrerPolicy": "strict-origin-when-cross-origin",
  "body": null,
  "method": "GET",
  "mode": "cors",
  "credentials": "include"
});

I also tried this, which also returns noting

var url = "https://hub.docker.com/v2/repositories/freddy0/crafty-container";

var xhr = new XMLHttpRequest();
xhr.open("GET", url);

xhr.onreadystatechange = function () {
   if (xhr.readyState === 4) {
      console.log(xhr.status);
      console.log(xhr.responseText);
   }};

xhr.send();

The Errors i get range from CORS policy denied to net::ERR_FAILED, Access to XMLHttpRequest at 'https://hub.docker.com/v2/repositories/freddy0/crafty-container/' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

When trying to get data via a different source i recieve a valid answer which i could work with : https://reqbin.com/0mfci8tl

Anyone got an idea how to accomplish this?

Freddy0
  • 1
  • 1

0 Answers0