Skip to main content

Publish a Static Web App on Azure

I had to create a small personal website. As a big fan of the Jamstack, I like to use a static website generator like next.js, gatsby or hugo. Before  I typically deployed this generated website on Azure Blob storage as a really cheap way to host a static website. But with the introduction of Azure Static Web Apps, it is time to give them a try…

Create a Gatsby static website

There is a large list of available website generators, but as I like GraphQL a lot, I decided to use Gatsby.

First install the gatsby cli:

npm install -g gatsby-cli

Now you can  create a new website on your local machine using one of the available themes:

npx gatsby new example-app https://github.com/LekoArts/gatsby-starter-portfolio-cara

Store the website on Github

We need to store the code of our static website somewhere. This could be a Git repo on Azure DevOps, Github or any other Git enabled repository.

We’ll use Github in this example.

Create a new Github repository at https://github.com/new. Choose a repository name but don’t create a README.md or .gitignore file.

Open a command prompt and go to the website folder on your local machine ( example-app in my example).

Add the newly created Github repo as a remote origin:

git remote add origin https://github.com//example-app

Let's push our code to the Github repo

git branch -M main
git push --set-upstream origin main

Create an Azure Static Web App

Almost there! We have finally arrived at the Azure part.

Go to the Azure portal at https://portal.azure.com. Click on ‘Create a resource’ at the top.

In the search field enter ‘Static Web App’ and hit <enter>. You’ll arrive at the following screen:

Click Create. Now you arrive at the creation screen where you have to enter a lot of details. Select a subscription and resource group and enter a name for your static web app. We choose the free tier and a region close to us.

As a last step we choose Github as our source. Now we need to authenticate with Github. Therefore click on Signin with Github to login with our Github credentials. 

Click on Authorize Azure-App-Service-Static-Web-Apps to grant the necessary permissions to Azure to manipulate our Github repo.

Now we need the Github repository and branch that should be used.

As a last step we can select the Gatsby presets from the Build Presets menu. This will create a default Github Actions workflow for us.

Now click on Review+Create and Create to create our Azure Static Web App.

If you browse to the generated website, you will probably see something like this:

This is because Github Actions still need to deploy and generate the static web app.

Once the Github Actions workflow completes, our Gatsby site is there in all it’s glory:

More information: https://docs.microsoft.com/en-us/azure/static-web-apps/

Popular posts from this blog

DevToys–A swiss army knife for developers

As a developer there are a lot of small tasks you need to do as part of your coding, debugging and testing activities.  DevToys is an offline windows app that tries to help you with these tasks. Instead of using different websites you get a fully offline experience offering help for a large list of tasks. Many tools are available. Here is the current list: Converters JSON <> YAML Timestamp Number Base Cron Parser Encoders / Decoders HTML URL Base64 Text & Image GZip JWT Decoder Formatters JSON SQL XML Generators Hash (MD5, SHA1, SHA256, SHA512) UUID 1 and 4 Lorem Ipsum Checksum Text Escape / Unescape Inspector & Case Converter Regex Tester Text Comparer XML Validator Markdown Preview Graphic Color B

Help! I accidently enabled HSTS–on localhost

I ran into an issue after accidently enabling HSTS for a website on localhost. This was not an issue for the original website that was running in IIS and had a certificate configured. But when I tried to run an Angular app a little bit later on http://localhost:4200 the browser redirected me immediately to https://localhost . Whoops! That was not what I wanted in this case. To fix it, you need to go the network settings of your browser, there are available at: chrome://net-internals/#hsts edge://net-internals/#hsts brave://net-internals/#hsts Enter ‘localhost’ in the domain textbox under the Delete domain security policies section and hit Delete . That should do the trick…

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.