dwyl / hits

:chart_with_upwards_trend: General purpose hits (page views) counter
http://hits.dwyl.com
GNU General Public License v2.0
422 stars 63 forks source link

Fetching JSON is blocked or return opaque answer #240

Open lx78WyY0J5 opened 1 year ago

lx78WyY0J5 commented 1 year ago

Hi, recentrly i found this repo, the badge work when using in simple HTML,

But today i started to think about just grabing the JSON returned with some JS

The only way i could get an "answer" is by forcing 'NO-CORS' & CrossOrigin But with this, it answer, but always an opaque "empty" response

I tested a LOT of way to fetch this .json that even my god damn browser show But none either respond (blocked by cross-origine (while active) or by CORS), or they just respond this

Code :

    return new Promise(function (resolve, reject) {
        setTimeout(() => {
            fetch(url, {
                method: 'GET',
                crossorigin: true,
                mode: 'no-cors'
            })
                .then(response => console.log(response))
                .then(data => {
                    console.log(data);
                    return;
                })
                .catch(error => console.error(error))
        }, 1000);
    });
}
var global = await gather('https://hits.dwyl.com/abc/abc');  

Response chrome_AlldM4NqMI


Edit : I tested it also with realTime page & console (to avoid running script from local IP 127.0.0.1...) But same behavior


cURL work well and give me the raw JSON as answer after hitting cloudflare,


Forgot to mention that else, everything work perfectly 🤡 😢 Thx BTW for repo :octocat: