๐ Welcome to the second episode of our Cloud App Journey series!
After learning how to authenticate with Azure services and how to publish our backend, today weโll focus on the frontend.
If youโre building a Single Page Application (SPA) with frameworks like React, Angular, or Vue, youโll see that publishing your app on Azure is simpler and cheaper than you might think.
๐ Choosing the Best Hosting Option
When publishing SPAs in Azure, you might think about using App Service (the same one we used for the backend).
But hereโs the trick: SPAs donโt need a full backend hosting environment.
Instead, the most efficient and cost-effective way is to use Azure Storage Static Website Hosting.
Why?
โ๏ธ Incredibly cheap (weโre talking cents per month).
โ๏ธ Extremely simple to configure.
โ๏ธ Built-in high availability.
โ๏ธ Integrates seamlessly with Azure CDN, for global distribution if needed.
๐ฆ Step 1: Preparing Your Build
If youโre using React, Angular, or another SPA framework, the first step is to build the production version of your app.
For example, in Angular:
ng build --configuration production
In React:
npm run build
This will generate a folder (usually called dist or build) with all the compiled static files (HTML, CSS, JS, and assets).
โ๏ธ Step 2: Creating a Storage Account
In Azure Portal:
Search for Storage Account.
Create a new account (standard performance is usually enough).
Go to the Static Website menu (inside the storage account).
Enable it and configure the index document (e.g., index.html) and error document (e.g., index.html as well, if youโre using SPA routing).
This will generate a public URL for your website, something like:
https://<your-storage-account>.zxx.web.core.windows.net
๐ Step 3: Uploading Your Files
There are different ways to upload your SPA build to the storage account:
Azure Portal: upload files directly in the browser.
Azure Storage Explorer (a free Microsoft tool).
Azure CLI:
az storage blob upload-batch \
--account-name <your-storage-account> \
--destination '$web' \
--source ./build
โก Step 4: (Optional) Adding a CDN
If your users are spread across different regions, you can easily integrate a CDN to ensure your frontend loads faster worldwide.
In the storage account:
- Go to Front Door and CDN.
- Create a new CDN profile.
- Link it to your static website endpoint.
Thatโs it โ now your SPA is globally distributed! ๐
๐ Wrapping Up
Publishing your frontend in Azure doesnโt have to be complicated or expensive.
With just a Storage Account, you get a secure, highly available, and low-cost hosting solution for your SPAs.
๐ In the next episode, weโll explore how to publish containerized App, front and/or backend apps.
๐ก Have you already tried publishing a frontend in Azure? What challenges did you face? Share your experience in the comments!
Top comments (0)