global-electrification-platform / explorer

Global Electrification Platform (Web)
https://electrifynow.energydata.info/
MIT License
11 stars 7 forks source link

CORS issue #212

Closed EricSoroos closed 4 years ago

EricSoroos commented 4 years ago

When serving the frontend on a different https domain than the backend, I'm getting a CORS error in the console:

/explore/et-1?year=2030&scenario=1_0_0_0_0_0&filters=r5_6371125%7Cr0_309%7C1_3_5_6_7%7Cr0_179%7Cr0_148%7Cr14_2135:1 
Access to fetch at 'https://gep-api.prod.derilinx.com/scenarios/et-1-1_0_0_0_0_0?year=2030' from origin 'https://drdvy1ij2aqxx.cloudfront.net' has been blocked by CORS policy: 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I'm not sure if we can do a no-cors on the front end, or if something needs to be set on the API server.

vgeorge commented 4 years ago

@EricSoroos the latest website version was deployed to gep-explorer-devseed-public bucket, using the following API URL:

https://gep-api-prod.us-west-2.elasticbeanstalk.com

As we already know, this endpoint doesn't serve HTTPS yet, so the site won't work. Once HTTPS is enabled, this CORS issue should be gone as the server should be adding the appropriate response headers.

EricSoroos commented 4 years ago

Can you push a new version with these urls:

vgeorge commented 4 years ago

Deployed and fixed.

EricSoroos commented 4 years ago

This (CORS error) still seems to happen if there's a timeout on the data service:

VM970:1 GET https://api.electrifynow.info/scenarios/ng-1-0_0_0_0_0_0?year=2030 502 (Bad Gateway)
(anonymous) @ VM970:1
(anonymous) @ bundle-1fff8315a0.js:1
X @ vendor-834745103f.js:1
P.u._invoke @ vendor-834745103f.js:1
ng-1?year=2030&scenario=0_0_0_0_0_0&filters=r8_2766837%7Cr0_190%7C1_3_5_6_7%7Cr0_131%7Cr0_68%7Cr15_2105:1 Access to fetch at 'https://api.electrifynow.info/scenarios/ng-1-0_0_0_0_0_0?year=2030' from origin 'https://electrifynow.info' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
VM970:1 Fetch failed loading: GET "https://api.electrifynow.info/scenarios/ng-1-0_0_0_0_0_0?year=2030".

Given that's it's a secondary error that happens on a fetch failure, I'm not sure that it's important.

vgeorge commented 4 years ago

I think this might be addressed by https://github.com/global-electrification-platform/explorer/issues/211 when done.