Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
1.98k stars 1.15k forks source link

Service Bus: Add CORS support for topic creation in the browser #23325

Open federicoder opened 1 year ago

federicoder commented 1 year ago

Describe the bug Hi all, i try to create a topic with javascript sdk for azure service bus from stencilJS library, but i receive always this error: (I receive the same error also when i import the webcomponent into angular, so i think it's not related to stencilJS the error):

image

This is the simple code i implemented following the official samples:

   this.sbAdministrationClient = new ServiceBusAdministrationClient(this.connectionString)
    this.checkOrCreateTopic();
async checkOrCreateTopic(){
     await this.sbAdministrationClient.createTopic("local-webcomponent")
  }

I can't create topics and queues from sdk, but when if i create topics by portal.azure.com, and i use sdk to create subscriptions and i can do it. Can someone help me please?

jeremymeng commented 1 year ago

@federicoder thank you very much for reporting the issue! I tried to repo locally in a vanilla HTML + bundled JavaScript code, but this similar code below worked fine for me (after disabling browser security for CORS). I wonder whether something went wrong when integrating with other framework. Is it possible for you to share a simplified project that demonstrates this issue?


async function checkOrCreateTopic(){
  const sbAdministrationClient = new ServiceBusAdministrationClient(connectionString);
  const response = await sbAdministrationClient.createTopic(topicName);
  console.log("##### topic created successfully");
  console.log(response);
}

image

federicoder commented 1 year ago

hi @jeremymeng , thank you for reply, I solved by disabling browser security for CORS. I have question: Is there a way to create a topic, without disabling cors security for broswer?

jeremymeng commented 1 year ago

@federicoder This is actually a known issue due to Service Bus backend service. I am going to ask the service team about the status again but currently I am not aware of a way other than disabling browser CORS security.

federicoder commented 1 year ago

okay thank you very much @jeremymeng , can we keep in touch if you will know something about this thing in future?

jeremymeng commented 1 year ago

@federicoder yes, we will keep this issue open and I will update here.