Static Web Apps - First Look
Tags: javascript, staticwebapps, webdev, beginners
Published: 2020-05-19 17:26:34

---
title: Static Web Apps - First Look
published: true
description: You've built an app and you want it to scale. Do you want CI/CD, custom domains, SSL certificates, APIs, global scale of your static assets, authentication, and authorization? Let's take a first look at Azure Static Web Apps.
tags: javascript, staticwebapps, webdev, beginners
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/ffg53zt5jsmifh8kx81p.png
canonical_url: https://johnpapa.net/static-web-apps-first-look
---

Let's start with a story that many of you are familiar with … you're building a web app. You chose your favorite framework. Maybe React or Angular or Vue or even Svelte. Your company wants to deploy the web app and reach millions of people.

So you start making a checklist of everything you need to do:

| Yes/No | What you need                           |
| ------ | --------------------------------------- |
| yes    | Develop your app                        |
| yes    | Code in GitHub                          |
| ?      | Pull Requests that create staging sites |
| ?      | CI/CD to build and deploy the app       |
| ?      | APIs that scale                         |
| ?      | Reverse proxy to connect app to API     |
| ?      | SSL certificate                         |
| ?      | Custom domain                           |
| ?      | Authentication                          |
| ?      | Authorization                           |
| ?      | Server side route control               |
| ?      | Global scale of your static web assets  |

Wow, you just wanted to build your app!

What if you could lean on a service to provide all of this?

Rather than build up several servers and pipelines to handle these concerns, you start looking for a service that "just works". Point the service to your app and go.

> You can visit the [documentation](https://docs.microsoft.com/azure/static-web-apps/?WT.mc_id=staticwebaps-blog-jopapa) to learn more. Or you can [try one of our hands-on tutorials at Microsoft Learn today!](https://docs.microsoft.com/learn/modules/publish-app-service-static-web-app-api/?WT.mc_id=staticwebaps-blog-jopapa)

## Azure Static Web Apps

Released at Microsoft Build, Azure Static Web Apps (SWA) takes your source code to global availability. So you can develop your app while Azure Static Web Apps automatically builds and hosts it.

Static web apps are commonly built using libraries and frameworks like Angular, React, Svelte, or Vue. These apps include HTML, CSS, JavaScript, and image assets that make up the application. Under a traditional web server architecture, these files are served from a single server along side any required API endpoints. SWA helps host your static assets in an optimized server and makes them available in multiple servers around the world. SWA also optionally hosts your APIs using Azure Functions. Then it sets up a single URL for your users to visit.

You'll get everything in the checklist above!

![Publishing a Web App involves a lot of work](https://media.giphy.com/media/RMej9a69H0gALzvUdP/source.gif)

## Getting started

The first step is to create an app!

If you need one to try this service out you can follow these steps. If you have your own app, you can skip these steps entirely and proceed to the next section.

1. Click on <https://github.com/johnpapa/shopathome/generate> to create a new repo
1. Give your repo a name and create the repo
1. Click the folder `.github/workflows` in the GitHub web interface
1. Click on the file with the pattern `azure-static-web-apps.****.yml`
1. Delete this file

It is important to delete the workflow file because you'll be creating your own very soon!

Now you have four apps! This is a monorepo with the same app written in Angular, React, Svelte and Vue, each in their respective folders.

The starter code includes the four apps and the starting point for an API that you'll use.

```files
├ angular-app  👈 The Angular client app
├ api          👈 The API (Azure Functions)
├ react-app    👈 The React client app
├ svelte-app   👈 The Svelte client app
└ vue-app      👈 The Vue client app
```

## Free Azure Trial

Next, you'll need an Azure account. Don't worry if you don't have one, you can use the free Azure trial. Did I say it was free? Good, because it's free.

Get your **[free trial here](https://azure.microsoft.com/free/?wt.mc_id=staticwebapps-blog-jopapa)**

## Go to the Azure Portal

So you have your code and an Azure account, now you can create a SWA resource for your app!

1. Go to the [Azure Portal here](https://portal.azure.com/?feature.customportal=false#create/Microsoft.StaticApp?wt.mc_id=staticwebapps-blog-jopapa)
1. Select your Azure subscription
1. Create a resource group (this is just like a folder to collect all of your Azure "stuff")
1. Name your SWA (ex: **shopathome-sample**)
1. Choose the region closest to you
1. Sign in with GitHub
1. Select your GitHub organization
1. Select your GitHub repository (ex: **shopathome**)
1. Select your branch (ex: **main**)

    ![Create a Static Web Apps resource](https://dev-to-uploads.s3.amazonaws.com/i/g8to8i42id3aqsqorkg3.png)
## Set your folder locations

1. Set your _App location_ to the javascript framework you prefer
  - Angular - **angular-app**  
  - React - **react-app**      
  - Svelte - **svelte-app**     
  - Vue - **vue-app**        
1. Set the _Api location_ to **api**
1. Set the _App artifact location_ to one of the following, based on the framework you chose:
  - Angular - **dist/angular-app** 
  - React - **build**            
  - Svelte - **public**           
  - Vue - **dist**             
1. Click the **Review + create** button
1. Click the **Create** button

    ![Set your folder locations](https://dev-to-uploads.s3.amazonaws.com/i/ox33d2fk461menf7wpjn.png)

## Go to your web site

Azure is now creating your resources. SWA will create a GitHub Action workflow file and commit it to your repository in the _.github/workflows_ folder. This file will watch the branch you selected for changes. When you push changes to the branch they will trigger the GitHub Action workflow to build and deploy your app to SWA!

1. Soon, you'll be presented with a button to **Go to Resource**. Click this
1. At the top of the page you'll see several links. Click the **GitHub Action Runs** link

   ![Create a Static Web Apps resource](https://dev-to-uploads.s3.amazonaws.com/i/j2exbzveb6ws5zc7cmfj.png)

1. You'll be brought to your GitHub Action. When it is complete, you'll see green arrows everywhere.

   ![GitHub Action](https://dev-to-uploads.s3.amazonaws.com/i/627j36sve9ydzgmx38ef.png)

1. Once the action has completed the build and deploy, you can go back to the portal and click the **URL** link to open your web app

Depending on which framework you chose to build, you should see one of the following apps!

![GitHub Action](https://dev-to-uploads.s3.amazonaws.com/i/cmgv1lp3juz3cp4ph7e3.png)

## Beyond the first look

Oh there is so much more you can do! You can add a custom domain with an SSL certificate, authentication, and authorization. You can make a changes in a new branch, make a pull request, and then have the GitHub Action build and deploy your changes to a staging/preview URL!

This may be your first look, but if you want to learn more you can try one of our hands-on tutorials at Microsoft Learn today!

- Static Web Apps Learn modules:
  - [Angular, React, Svelte, or Vue JavaScript app and API](https://docs.microsoft.com/learn/modules/publish-app-service-static-web-app-api/?WT.mc_id=staticwebaps-blog-jopapa)
  - [Static web app with the Gatsby static site generator](https://docs.microsoft.com/en-us/learn/modules/create-deploy-static-webapp-gatsby-app-service/?WT.mc_id=staticwebaps-blog-jopapa)
- [Static Web Apps docs](https://docs.microsoft.com/en-us/azure/static-web-apps/?WT.mc_id=staticwebaps-blog-jopapa)
- [Static Web Apps announcement](https://techcommunity.microsoft.com/t5/azure-app-service/introducing-app-service-static-web-apps/ba-p/1394451?WT.mc_id=staticwebaps-blog-jopapa)