I am using following Web Works script to call Rest API KSQL DB call. This works fine from Postman but it is failing with response code 403 forbidden error from this script on fetch(url):
onmessage = async (event) => {
const url = “https://pksqlc-**.eastus.azure.confluent.cloud:443/ksql”;
const body = {
ksql: "show streams;",
streamsProperties: {}
};
let headers = new Headers();
headers.append(“Accept”, “application/vnd.ksql.v1+json”);
headers.append(“Content-Type”, “application/json”);
headers.append(“Access-Control-Allow-Origin”, “*”);
headers.append(“Access-Control-Allow-Methods”, “GET, POST, PATCH, PUT, DELETE, OPTIONS”);
headers.append(“Access-Control-Allow-Headers”, “Origin, Content-Type, X-Auth-Token”);
headers.append(“Authorization”,“Basic *******d3k1”);
console.log(‘Worker - Before post call’);
const response = await fetch(url, {
mode: “no-cors”,
method: “POST”,
headers: headers,
body: JSON.stringify(body),
});
const reader = response.body.getReader();
function push() {
// “done” is a Boolean and value a “Uint8Array”
reader.read().then(({ done, value }) => {
if (done) {
return;
}
// get the data chunk and post a message to main thread
const streamData = new TextDecoder().decode(value);
postMessage(streamData);
// try to read new message
push();
});
}
push();
};
I appreciate any help!
Thanks
Krishna