I have created a public API in my org and I am trying to call from Javascript which is hosted as static resource in same org. But Salesforce refused to connect public api.
I have tried CORS, Remote Site Settings, CSP Setting.
async function getUserAsync(name)
{
let response = await fetch('https://<api url>/services/apexrest/api-ws/',
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: '{}'
});
let data = await response.json()
return data;
}
getUserAsync()
.then(data => console.log(data));
Refused to connect to 'https://api_url/services/apexrest/api-ws/' because it violates the following Content Security Policy directive: "connect-src 'self' https://org.lightning.force.com *.visualforce.com https://org.documentforce.com https://org_instance.salesforce.com".
PS: Might be it is not good approach but I have a specific requirement.