I built a static web app and the html page is on one of my respositories. I built the API and it is on another repository. How do I link the two? Can I link the two? Or should I build a new static web app in the API repository?
-
Please provide enough code so others can better understand or reproduce the problem. – Community Dec 23 '21 at 11:53
1 Answers
You can link an existing Azure Functions app to an Azure Static Web Apps resource using 'Bring your own functions to Azure Static Web Apps'.
Example
Consider an existing Azure Functions app that exposes an endpoint via the following location.
https://my-functions-app.azurewebsites.net/api/getProducts
Once linked, you can access that same endpoint through the api path from your static web app, as shown in this example URL.
https://red-sea-123.azurestaticapps.net/api/getProducts
Both endpoint URLs point to the same function.
Link an existing Azure Functions app
Before you associate an existing Functions app, you first need to adjust to configuration of your static web app.
Set api_location value to an empty string ("") in the workflow configuration file.
Open your Static Web Apps instance in the Azure portal.
From the Settings menu, select Functions.
From the Environment dropdown, select Production.
Next to the Functions source label, select Link to a Function app.
From the Subscription dropdown, select your Azure subscription name.
From the Function App dropdown, select the name of the existing Functions app you want to link to your static web app.
Select the Link button.
Deployment You're responsible for setting up a deployment workflow for your Azure Functions app.
See steps and more info here

- 346
- 2
- 4
- 15