Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Custom forge app error cors external api

Alessandro Volpato
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 5, 2024

Hi, I am creating an issue panel and i need to make a call to an external mongodb endpoint. I have configured a function in the following way

async function sendDataToDB() {

const response = await fetch('https://westeurope.azure.data.mongodb-api.com/app/data-tgmerrf/endpoint/data/v1/action/insertOne', {

method: 'POST',

headers: {

'Content-Type': 'application/json',

'api-key': 'KEY',

'Access-Control-Allow-Origin': '*'

},

body: JSON.stringify({

"collection": "collection",

"database": "db",

"dataSource": "datasource",

"document": {

"name": "John Sample",

"age": 42

}

})

});

const data = await response.json();

return data;

}


the problem is that it gives me cors error

Access to the fetch of 'https://westeurope.azure.data.mongodb-api.com/app/data-tgmerrf/endpoint/data/v1/action/insertOne' from the source 'http://localhost:8000' was blocked by the CORS policy: Response to preflight request fails access control: 'Access-Control-Allow-Origin' header is not present on the requested resource. If you need an opaque response, set the request mode to 'no-cors' to retrieve the resource with CORS disabled. I

also tried putting mode: 'no-cors' but headers api-key is not used and therefore does not do authentication How can I solve the problem? Translated with DeepL.com (free version)

1 answer

0 votes
marc -Collabello--Phase Locked-
Community Champion
July 5, 2024

This is not a solution to your problem, but you are exposing the mongodb keys to your users.  That means a hacker can get access to your db.

It would be much better to call Mongo from the Forge backend, thereby not exposing the key.  In the backend calls, there will also be no CORS errors.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events