1

I've been getting a little lost down the rabbit hole of all things azure and blazor and I could use a little direction.

I'd like to create a blazor web assembly application that can deploy to an azure static web app where the application can communicate directly to cosmos db from the users browser without an azure function as it should speed up the response a bit.

I know there are issues with using the standard cosmos db client code since I will get cors errors.

It looks like there might be some workaround for that by generating a token based on a azure active directory user?

It seems like communicating directly with cosmos db from the browser would be ideal since it follows the whole faster serverless web approach but i'm just not sure the best way to accomplish this.

Is this something microsoft even wants us to do? Seems like everything is pushing towards servers and functions but if we had a client id and secret i dont think those would be needed...

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
Kyle Fuller
  • 117
  • 2
  • 13

1 Answers1

1

You can try out the new toolset that we have added , Data API builder which has integration with Azure Static Web apps to build your Graphql endpoints on top of Azure Cosmos DB .

You just need to provide the schema of the Cosmos DB collection and link the database rest is done automatically by the feature.

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • Thank you for your reply, I've been going through this tutorial: https://learn.microsoft.com/en-us/azure/static-web-apps/database-azure-cosmos-db?tabs=powershell It's not using blazor so i'm not sure how to handle the step where it asks me to run the static-web-app-cli I get the following error when i run the blazor app and that at the same time: System.IO.IOException: 'Failed to bind to address http://127.0.0.1:5000: address already in use.' – Kyle Fuller Mar 23 '23 at 20:11
  • FYI this should be a comment, not an answer (as it's general advice, not something specific) – David Makogon Mar 23 '23 at 20:44
  • @KyleFuller Looks like you are already using the port 5000, kill the port and restart – Sajeetharan Mar 24 '23 at 03:46
  • Well i think since i'm adding this to my blazor application i can just run normally with visual studio as opposed to using the static-web-app-cli right, or is that needed for this to work? However i dont seem to be able to get around the cors errors despite following that tutorial. – Kyle Fuller Mar 24 '23 at 14:35
  • Thats right, you need to run using the cli. CORS should be handled out of the box, or just add the url in the cors section of the config – Sajeetharan Mar 24 '23 at 15:30