We've just released v0.9.0 of the Azure Static Web Apps extension for VS Code. This release includes features to help debug your static web app locally, including Azure Functions API routes, authentication, and routing.
If you're new to Azure Static Web Apps, I highly recommend checking out the What is Azure Static Web Apps? documentation page.
In this post, we'll learn how to get started debugging a static web app locally. Then we'll add an Azure Functions API route, and debug our backend + frontend together.
Google Chrome installed, (we make use of the debugger)
Azure Static Web Apps extension for VS Code - View on Marketplace
Azure Static Web Apps CLI 0.8.0 or greater - View on GitHub
npm install -g @azure/static-web-apps-cli@latest
- Clone one of these repositories, and open it up in VS Code.
- Go to the "Run and Debug" view.
- Click "Show all automatic debug configurations."
- In the dropdown, select "Azure Static Web Apps...".
- Select the app you want to debug.
This will start the Azure Static Web Apps CLI in the VS Code terminal, and launch the Chrome debugger on
Now you can set and hit breakpoints in your frontend code.
Azure Static Web Apps has integrated API support provided by Azure Functions. In order to add and debug an API route, we must install some Azure Functions tools.
Azure Functions extension for VS Code - Install from Marketplace
Azure Functions Core Tools - View on GitHub
npm i -g azure-functions-core-tools@3 --unsafe-perm true
Now, you can add an API route to your app by clicking the "Add HTTP Function..." button in the Azure Static Web Apps view.
We can debug our API routes and our frontend app simultaneously in VS Code.
Select the "SWA: Run ..." debug configuration and click the green "Run and debug" button.
VS Code will now run your Functions API routes and your frontend. When it's all started, a Chrome window will open at
Set a breakpoint in your Function endpoint.
http://localhost:4280/api/hello in the Chrome window to hit the breakpoint.
Now that you got your static web app running locally, you can deploy your static web app to Azure for free.
If you're having issues, please check out the troubleshooting section in our wiki.
Hello 👋 I'm Alex 🤠 and I'm a developer working on the Azure Static Web Apps extension for VS Code. I hope you enjoyed the post!