Share via

Static Web App and Web App

Tengku Aiman 120 Reputation points
2026-05-13T13:02:11.6466667+00:00

Hello, I have several question about static web app, web app, postgresql, cosmosDB and virtual machine. To help my question, I have my architectural diagram on the system that will be developed.

Web Development

  1. Is there any way that I can connect the static web app and backend? I have tried using the environment variables, and github secrets, but it seems that they cannot communicate
  2. Right now when developing, I can connect the backend with the db and storage account, in the production, it is okay to use environment variable right?

Thank you for your help!!

Azure Static Web Apps
Azure Static Web Apps

An Azure service that provides streamlined full-stack web app development.

0 comments No comments

Answer accepted by question author

  1. TP 156.6K Reputation points Volunteer Moderator
    2026-05-13T13:46:02.0933333+00:00

    Hi,

    Q: Is there any way that I can connect the static web app and backend? I have tried using the environment variables, and github secrets, but it seems that they cannot communicate

    A: One way to link your Static Web App (SWA) to your backend is to use the built-in capability to proxy requests to /api to your app service. SWA Environment variables are for managed functions (which you aren't using). For reference:

    API support in Azure Static Web Apps with Azure App Service

    https://learn.microsoft.com/en-us/azure/static-web-apps/apis-app-service

    Basic instructions to link to your backend are below:

    Navigate to your static web app in portal, on left, click on Settings -- Hosting Plan. Select Standard and click Save.

    swa1

    Click on Settings -- APIs. Click on Link next to Production.

    swa2

    Select Web App, select your Subscription, select your app service, select slot, click Link, similar to below screenshot:

    swa3

    Q: Right now when developing, I can connect the backend with the db and storage account, in the production, it is okay to use environment variable right?

    A: Yes, it is okay to use environment variables. In your case you are using them in your app service. You may consider storing sensitive variables in key vault (from your diagram it appears you may already doing this).

    Please click Accept Answer and upvote if the above was useful.

    Thanks.

    -TP

    Was this answer helpful?

    1 person found this answer helpful.

Answer accepted by question author

  1. Praneeth Maddali 9,520 Reputation points Microsoft External Staff Moderator
    2026-05-13T13:37:18+00:00

    Hi @Tengku Aiman

    Thank you for your message and for sharing the architecture diagram — it’s really helpful to see the full picture.

    1. Is there any way that I can connect the static web app and backend?

    Yes, you can connect your Static Web App to the Web App backend effectively. The reason environment variables and GitHub secrets didn’t allow direct communication is because Static Web Apps are static hosting by default, and client-side code can’t easily call a separate backend without proper configuration.

    Recommended Solution: Use Azure Static Web Apps’ “Bring Your Own API” feature. This links your Web App as the backend and automatically proxies requests (e.g. fetch('/api/...')) from the frontend to your backend — no CORS headaches and much cleaner.x`
    How to set it up:

    Go to your Static Web App in the Azure Portal.

    Navigate to APIs in the left menu.

    Under the Production environment, click Link.

    Select Web App and choose your backend App Service.

    Click Link.

    Once linked, update your frontend to call relative paths like /api/your-endpoint.

    Reference:

    https://learn.microsoft.com/en-us/azure/static-web-apps/apis-app-service

    https://learn.microsoft.com/en-us/azure/static-web-apps/apis-overview

    1. Using Environment Variables in Production

    Yes, it is perfectly fine and very common to use environment variables (App Settings) in production for your Web App backend.

    However, for better security with PostgreSQL, Cosmos DB, Storage Account, etc., I strongly recommend combining App Settings with Managed Identity (as shown in your diagram with aslaw-kv and aslaw-MI). This avoids storing sensitive connection strings in settings whenever possible.

    You can continue using environment variables during local development and switch to the same approach in production.

    Reference :

    https://learn.microsoft.com/en-us/azure/app-service/overview-managed-identity?tabs=portal%2Chttp

    If the answer is helpful,  Please do click "Accept the answer” and Yes, this can be beneficial to other community members.

    If you have any other questions, let me know in the "comments" and I would be happy to help you

    Was this answer helpful?

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.