I am having an absolutely dismal time with #azure static web apps do NOT recommend.

Not least having to type out ‘azure static web apps’ every time I google for a feature it turns out not to support 🙄

#azureStaticWebApps #dismal #webdev

@felixthehat Intrigued to know what you've bumped on Felix. I've been a long time user of SWAs and had a very good time with them! My blog is hosted on them and I use them for a number of work apps too. What's been tricky for you?

A static web app of mine: https://johnnyreilly.com/

johnnyreilly | johnnyreilly

The blog of John Reilly ❤️🌻

@johnny_reilly ah! I should have thought to ask you! currently I’m fighting 2 issues,

1. trying to set different environment variables for my front end app, a staging and prod var – app settings seem to be ignored and always uses ‘production’, and github actions yaml only allows for one env?

2. I can’t figure out how to point custom domains to my staging branch…

have you come across these issues?

@felixthehat So with environment variables, it's worth remembering that at runtime all you have is the build output and so environment variables are only useful at build time. You can see an example of me using an environment variable in my build here:

https://github.com/johnnyreilly/blog.johnnyreilly.com/blob/b5597405de749d24e59a8e954225744b7a6ea3f2/blog-website/docusaurus.config.js#L4

You can see the environment variables being supplied in GitHub actions here:

https://github.com/johnnyreilly/blog.johnnyreilly.com/blob/b5597405de749d24e59a8e954225744b7a6ea3f2/.github/workflows/build-and-deploy-static-web-app.yml#L148

With this in hand, you should be able to customise your build based on those variables

blog.johnnyreilly.com/blog-website/docusaurus.config.js at b5597405de749d24e59a8e954225744b7a6ea3f2 · johnnyreilly/blog.johnnyreilly.com

This is the source code for https://johnnyreilly.com - johnnyreilly/blog.johnnyreilly.com

GitHub

@felixthehat On custom domains for staging I have 2 thoughts.

If you're using the built in staging environments, I don't think you can use custom domains.

However. SWAs are pretty much free (or so cheap they are nearly free). Why not spin up another SWA for your staging environment? Then you can happily use a custom domain. And your GitHub actions won't be particularly complicated. I do this already for some internal apps

@johnny_reilly oh so the application settings don’t do anything?

my (mostly auto generated) yaml file doesn’t seem to have a similar run command.

that duplicate app idea has potential! this is my first attempt at ASWA and github actions and I do not know what I’m doing.

I miss netlify which has a GUI for all this crud lol

@felixthehat So I missed a key piece of information out! Azure Static Web Apps build by themselves by default. This works pretty well generally, until you want to do something slightly custom. Environment variables fits into that category; you'll want to do the build externally to Oryx and supply the artifact. I've written about this here:

https://johnnyreilly.com/azure-static-web-apps-build-app-externally

And you can see it done in my blog here:

https://github.com/johnnyreilly/blog.johnnyreilly.com/blob/b5597405de749d24e59a8e954225744b7a6ea3f2/.github/workflows/build-and-deploy-static-web-app.yml#L144-L168

Azure Static Web Apps: build app externally | johnnyreilly

Azure Static Web Apps can generally build themselves with Oryx. If you need finer grained control of your build, you can with `skip_app_build: true`.

@felixthehat As to Application Settings, they have some uses for the front end, but they are pretty niche. Mostly Application Settings are used if you want to parameterise the built in function app. Again you can see this in action on my blog https://github.com/johnnyreilly/blog.johnnyreilly.com/blob/b5597405de749d24e59a8e954225744b7a6ea3f2/blog-website/api/fallback/saveToDatabase.ts#L6
blog.johnnyreilly.com/blog-website/api/fallback/saveToDatabase.ts at b5597405de749d24e59a8e954225744b7a6ea3f2 · johnnyreilly/blog.johnnyreilly.com

This is the source code for https://johnnyreilly.com - johnnyreilly/blog.johnnyreilly.com

GitHub
@johnny_reilly thanks! I will read over your blog. I would argue an environment variable is hardly much of an ask but I will have a poke around! have you ever used netlify or vercel?

@felixthehat Yeah - my blog used to run on netlify / GitHub pages. I got burned for build minutes there and pivoted to SWAs. I wrote about the migration here:

https://johnnyreilly.com/azure-static-web-apps-a-netlify-alternative

TL;DR - I think they're pretty awesome and I've got some contacts on the team as well who've been able to help when I've found rough edges

Azure Static Web Apps - a Netlify alternative | johnnyreilly

Azure Static Web Apps are a new offering from Microsoft. This post looks at what they are and how they compare to Netlify.

@felixthehat If there's stuff you get stuck with, let me know. I'd be happy to jump on a call and assist. And if it's something which isn't possible, I might be able to connect you and the team; they are super helpful

@johnny_reilly I certainly have a few, let’s call them ‘suggestions’ for them lol

thank you I do appreciate your help. I see you have env vars in your yaml! you can’t set them per environment no?

One other thing I’m missing from netlify, they allow you to create a webhook url that when called triggers a build. is that a thing on swa/google actions? cheers!

@felixthehat > I see you have env vars in your yaml! you can’t set them per environment no?

In that you can control the value of the environment variable in GitHub actions, I think you can inject different values for each environment. So I think that should work

@felixthehat > One other thing I’m missing from netlify, they allow you to create a webhook url that when called triggers a build

Given that the build is triggered by GitHub actions, you probably want this:

https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads

I've never done it - but it looks like it's supported

Webhook events and payloads - GitHub Docs

Learn about when each webhook event occurs and what the payload contains.

GitHub Docs

@felixthehat I think a key distinction to draw is that Netlify is a CI/CD and web platform combined.

Azure Static Web Apps is a web platform. GitHub Actions is the CI/CD. They're separate; not combined.

That said, my own experience has been that SWAs can do all netlify can do and more, just not necessarily in the same ways.

@johnny_reilly yeah it seems to be a yaml-a-thon. looking into it I think your idea for two sites might be workable thanks!
@felixthehat If you hit any bumps then hit me up - happy to assist