freakimkaefig / uebersicht-newsticker-widget

A news ticker for Übersicht using newsapi.org
MIT License
3 stars 1 forks source link

TyperError #3

Open coolajami opened 4 years ago

coolajami commented 4 years ago

Hi Your widget is amazing! Worked well for a long time, but recently it does not load and I'm getting the following error message:

"We got an error: TyperError: Origin http://127.0.0.1:41416 is not allowed by Access-Control-Allow-Origin."

I'm not sure if it's a localhost problem, but it does work for other applications. It start happening since the last major MacOs update. Any ideas?

katlou commented 4 years ago

I'm not related to @freakimkaefig or the project, but my guess is newsapi.org clamped down on their CORS policy. One workaround I found is to use curl instead of the built in proxy, i.e.

replace both instances of

fetch(url.href)
    .then(response => {
        return response.json();
    })
    .then(data => {
        return dispatch({
            type: 'FETCH_SUCCEEDED',
            data: data
        });
    })
    .catch(error => {
        return dispatch({
            type: 'FETCH_FAILED',
            error: error
        });
    });

with

run("curl --silent '" + url.href + "'")
    .then((output) => {
        return dispatch({
            type: 'FETCH_SUCCEEDED',
            data: JSON.parse(output)
        });
    });

and remember to import run, i.e. import { css, run } from 'uebersicht';

Hope this helps someone!

coolajami commented 4 years ago

I'm not related to @freakimkaefig or the project, but my guess is newsapi.org clamped down on their CORS policy. One workaround I found is to use curl instead of the built in proxy, i.e.

replace both instances of

fetch(url.href)
    .then(response => {
        return response.json();
    })
    .then(data => {
        return dispatch({
            type: 'FETCH_SUCCEEDED',
            data: data
        });
    })
    .catch(error => {
        return dispatch({
            type: 'FETCH_FAILED',
            error: error
        });
    });

with

run("curl --silent '" + url.href + "'")
    .then((output) => {
        return dispatch({
            type: 'FETCH_SUCCEEDED',
            data: JSON.parse(output)
        });
    });

and remember to import run, i.e. import { css, run } from 'uebersicht';

Hope this helps someone!

Hi thanks, your solution is actually work pretty well! The sticker now works normally when loads with the Ubersicth, but if you try to use a keyboard interaction with one of the categories the error appears again.

wardspan commented 4 years ago

went with a bit more simplistic solution:

added cors-anywhere proxy to the front of the const BASE_URL like this:

const BASE_URL = 'https://cors-anywhere.herokuapp.com/http://newsapi.org/v2/top-headlines?';

The bonus to this solution is that links work, the biggest concern here is that you are sharing your api token with Rob Wu who provides the proxy.