Azure Static Web App NodeJS env variables

Viewed 2024

I'm using Azure Static Web App service and Azure DevOps pipeline to deploy a NodeJS app. The pipeline and the build are going well. Now i have to define a URL for the backend using env variables, but without success.

trigger:
- develop

jobs:
  - job: JobTest
    pool:
      vmImage: ubuntu-latest

    variables:
    - name: BACKEND_URL
      value: https://<some_url>
    - name: System.Debug
      value: true
    steps:
    - task: AzureStaticWebApp@0
      inputs:
        app_location: "/" 
        api_location: ""
        output_location: "dist"

      env:
        BACKEND_URL: $(BACKEND_URL)
        azure_static_web_apps_api_token: $(deployment_token)
    - bash: echo $(BACKEND_URL)
    - bash: echo $PWD

and from the NodeJS code, in the "/app/src/models/config.ts" file i have the this:

export const BACKEND_URL = process.env.BACKEND_URL

If i change process.env.BACKEND_URL with the actual URL it will work.

Also, from the Azure Pipeline this task is using the https://github.com/microsoft/Oryx build system.

The question is how can i use env from the pipeline in the code?

2 Answers
Related