MagicMirror icon indicating copy to clipboard operation
MagicMirror copied to clipboard

weather module for ukmetoffice showing cors error

Open sdetweil opened this issue 2 years ago • 12 comments

Access to XMLHttpRequest at 'http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/94004601?res=3hourly&key=fribble' from origin 'http://0.0.0.0:8090' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Access to XMLHttpRequest at 'http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/94004601?res=3hourly&key=fribble' from origin 'http://localhost:8090' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

		{
			module: "weather",
			position: "top_right",
			config: {
        weatherProvider: "ukmetoffice",
        apiBase :'http://thingproxy.freeboard.io/fetch/http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/',
        locationID: "94004601",
        apiKey: "fribble"
         }
}

should fail with unauthorized as fribble is a bad apikey

this is the generated url request

http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/94004601?res=3hourly&key=fribble

2.17,1

sdetweil avatar Nov 26 '21 18:11 sdetweil

The used cors-provider in darksky provider https://cors-anywhere.herokuapp.com/ seems to work (instead of http://thingproxy.freeboard.io/fetch/).

Getting now expected 401 (have no key).

khassel avatar Nov 26 '21 20:11 khassel

when I do this (prefix the provider generated url with the herokuapp proxy link )

https://cors-anywhere.herokuapp.com/http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/94004601?res=3hourly&key=fribble

I get a a nothing here yet page Screenshot at 2021-11-27 09-49-52

sdetweil avatar Nov 27 '21 15:11 sdetweil

I'm seeing a similar cors error using the envcanada weather provider.

Config.js entry:

{
    module: "weather",
    position: "top_left",
    config: {
        weatherProvider: "envcanada",
        siteCode: 's0000098',
        provCode: "QC",
        type: "current",
        showPeriod: false,
        showHumidity: true,
        location: "Salaberry-de-Valleyfield"
    }
},

console error:

Access to XMLHttpRequest at 'https://thingproxy.freeboard.io/fetch/https://dd.weather.gc.ca/citypage_weather/xml/QC/s0000098_e.xml' from origin 'http://192.168.x.x:xxxx' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

jptrsn avatar Jan 12 '22 21:01 jptrsn

I can confirm this error. So using https://thingproxy.freeboard.io/fetch/ as cors proxy seems not to work anymore. It is difficult to find a working one, the above mentioned https://cors-anywhere.herokuapp.com/ now wants a button click in the web ui before you can use it ...

khassel avatar Jan 13 '22 22:01 khassel

@jptrsn the above PR is merged so you could test if envcanda works now. You have to use the develop branch for testing this (next official release is 1.April). I would recommend to clean up (rm -rf node_modules) and run a new npm install --only=prod.

@sdetweil while testing this I had no problems with ukmetoffice when running without a cors proxy. If you still have cors problems with this provider you could also test the develop branch and add useCorsProxy: true, in the config:

                {
                        module: "weather",
                        position: "top_right",
                        config: {
                                weatherProvider: "ukmetoffice",
                                useCorsProxy: true,
                                locationID: "322942",
                                apiKey: "xxx"
                        }
                },

Let me know if it works.

khassel avatar Jan 28 '22 20:01 khassel

ok, wasn't me directly. will advise the user

sdetweil avatar Jan 28 '22 21:01 sdetweil

I'm using a docker-based approach, so I will wait on the next production release and rebuild the image. Currently don't have any dedicated hardware for this.

jptrsn avatar Feb 18 '22 17:02 jptrsn

o.k., if it is an option for you: the image karsten13/magicmirror:develop contains the develop branch of this repo ...

khassel avatar Feb 18 '22 18:02 khassel

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 27 '22 17:04 stale[bot]

this doesn't work for ukmetofficehub.. doesnt use the provider fetchData... garf..

sdetweil avatar Jun 29 '22 15:06 sdetweil

tested ukmetofficehub without any problems

khassel avatar Jun 29 '22 20:06 khassel

I just tested on 2.20, develop, and it doesn't call providers/fetchData.. so can't get cors fix.

send me email, I can provide failing apikey info same userid at gmail

sdetweil avatar Jun 29 '22 21:06 sdetweil

@sdetweil can this be closed?

khassel avatar Oct 02 '22 22:10 khassel