ohcnetwork / life

Verified Crowd-Sourced Emergency Services Directory
https://life.coronasafe.network/
82 stars 56 forks source link

life-pipeline API doesn't work when accessing it from localhost #281

Closed Fayiz-A closed 3 years ago

Fayiz-A commented 3 years ago

Describe the bug Related to this issue. I got this error while trying to access the api url: https://life-pipeline.coronasafe.network/api/resources?resource=SOMERESOURCE&state=SOMESTATE&district=SOMEDISTRICT as referenced on this page.

Note: Replace the capital words with resource, state and district respectively.

Error Access to XMLHttpRequest at 'https://life-pipeline.coronasafe.network/api/resources?resource=oxygen&state=delhi_(nct)&district=new_delhi' from origin 'http://localhost:53922' has been blocked by CORS policy.

Note: The api works if we hit it from the search bar of chrome or from postman but it doesn't work when hitting from localhost

To Reproduce Steps to reproduce the behavior:

  1. Fetch the API while running the code of fetching the API from localhost. You may run the Javascript code given below:
fetch("https://life-pipeline.coronasafe.network/api/resources?resource=oxygen&state=delhi_(nct)&district=new_delhi").then((data) => console.log(data));
  1. Check the console in chrome.
  2. You will see the error stated before.

Expected behavior The API should return the result even when running on localhost.

Proposed Solution Maybe this has to do something with HTACCESS File. It's a server side issue. In all the Stack Overflow Answers I have seen, this is the most proposed and the most popular solution. For example, see this Stack Overflow Answer

Desktop (please complete the following information):

Smartphone (please complete the following information): NA

Additional context Please look into this issue as soon as possible as it is blocking my development.

shrihari689 commented 3 years ago

Resolved via https://github.com/coronasafe/life-data/pull/6 📌