appsmithorg / appsmith

Platform to build admin panels, internal tools, and dashboards. Integrates with 25+ databases and any API.
https://www.appsmith.com
Apache License 2.0
32.3k stars 3.5k forks source link

[Bug]: Fetch CORS issue #34152

Open gootik opened 3 weeks ago

gootik commented 3 weeks ago

Is there an existing issue for this?

Description

When I use fetch() on the client side it cannot load resources because of CORS issue.

Steps To Reproduce

  1. Go to Edit mode of any application
  2. create a custom JS function
  3. add a fetch operation like await fetch('https://api.ipify.org?format=json')
  4. See that browser blocks call with "CORS Missing Allow Origin" error

Public Sample App

No response

Environment

Production

Severity

High (Blocker to building or releasing)

Issue video log

No response

Version

Self Hosted - v1.27

Nikhil-Nandagopal commented 3 weeks ago

@gootik we'll look into this. In the meanwhile, you can hit that URL using the regular API query

Screenshot 2024-06-11 at 12 48 49 PM
gootik commented 3 weeks ago

Thank you @Nikhil-Nandagopal , for this specific issue we would want the call to be from the Client side not server side. so the regular API query would not be sufficient :( Unless we can force the API query to run from client rather than appsmith server?

rishabhrathod01 commented 3 weeks ago

@gootik Could you please share the exact error you notice in the browser by sharing a screenshot of the same?

Also, the implementation for extracting the JSON with a fetch for your case should be as shown below.

async myFun2 () {
    return await fetch('https://api.ipify.org?format=json').then(res => res.json())
}