1. Check the SWA Plan
Ensure your SWA is on the Standard or Dedicated plan. The “Bring your own API” feature is not available on the free plan.
2. Configure the GitHub Workflow File
In the GitHub workflow file (azure-static-web-apps-<name>.yml), set the api_location to an empty string:
api_location: ""
This tells SWA not to manage internal functions and allows you to link an external backend.
3. Remove Managed Functions (If Any)
If your SWA already has managed functions, remove them before linking an external backend. This can be done in the Azure portal or the workflow file.
4. Link the Backend in the Azure Portal
In the Azure portal:
- Go to your SWA.
- Select APIs in the navigation menu.
- Click Link in the production line.
- Choose App Service as the backend type.
- Select your subscription, resource name, and desired App Service slot.
- Click Link.
This will link your backend to the /api path of the SWA.
5. Check Authentication Configuration
After linking, SWA creates an identity provider called “Azure Static Web Apps (Linked)” in the App Service. If you want the backend to be publicly accessible, remove this identity provider in the App Service authentication settings.
Possible Errors and Solutions
- Error: “Cannot link backend with a preexisting Azure Static Web Apps configuration”
This error may occur if the SWA already has a managed functions configuration. Ensure you remove any previous configurations before linking a new backend. - Backend Not Working After Linking
If the backend is not working after linking, wait for 30 to 60 minutes for configurations to propagate. Also, check if the backend health endpoint is accessible directly (without going through SWA) to diagnose connectivity issues.