question

ScottM-7356 avatar image
0 Votes"
ScottM-7356 asked PeterWidmer-6252 commented

Azure Static Web Site / CORS question

For Azure Static Web site, how do you deal with the issue when SPA (angular app) needs to make cross domain api call? Seems like CORS would be needed in this scenario but not sure how to address CORS with static web site.

azure-webapps
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Grmacjon-MSFT avatar image
0 Votes"
Grmacjon-MSFT answered PeterWidmer-6252 commented

Hi @ScottM-7356

Updating my earlier response --

CORS is not supported with static website but CORS is handled automatically for Azure Static Web App. When you call a Functions endpoint from a static page in an Azure Static Web Apps site, all the CORS settings are set up for you by default.

You can get started with Azure Web Apps with Angular following this tutorial.


Hope that helps.

-Grace


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

In case you need to develop locally with the Azure-Functions from your website, you can disable the security-features of Chrome.
This makes it at least possible to use fetch-api (or xmlhttprequest) on your local machine.

You can start chrome like this:
"<YOUR PATH TO CHROM>\chrome.exe" --disable-site-isolation-trials --disable-web-security --user-data-dir="c:\temp"

0 Votes 0 ·
TomislavMarkovski-6637 avatar image
0 Votes"
TomislavMarkovski-6637 answered TomislavMarkovski-6637 published

A good approach would be to setup a CDN for your static website and configure CORS. This works with static websites setup on a storage account or regular web app service.

https://docs.microsoft.com/en-us/azure/cdn/cdn-cors

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.