Azure Static Web Apps에 대한 애플리케이션 설정 구성

애플리케이션 설정에는 데이터베이스 연결 문자열과 같이 변경될 수 있는 구성 값이 포함됩니다. 애플리케이션 설정을 추가하면 애플리케이션 코드를 변경하지 않고도 앱에 대한 구성 입력을 수정할 수 있습니다.

애플리케이션 설정:

  • 정적 웹앱의 백 엔드 API에 대한 환경 변수로 사용할 수 있습니다.
  • 인증 구성에 사용되는 비밀을 저장하는 데 사용할 수 있습니다.
  • 미사용 시 암호화
  • 스테이징 및 프로덕션 환경에 복사됨
  • 영숫자와 ., _만 포함 가능

Important

이 문서에서 설명하는 애플리케이션 설정은 Azure Static Web App의 백 엔드 API에만 적용됩니다.

프런트 엔드 웹 애플리케이션을 빌드하는 데 필요한 환경 변수를 구성하려면 빌드 구성을 참조하세요.

필수 조건

  • Azure Static Web Apps 애플리케이션
  • Azure CLI - 명령줄을 사용하는 경우에 필요합니다.

로컬 개발을 위한 API 애플리케이션 설정 구성

Azure Static Web Apps의 API는 Azure Functions로 제공되며, 이를 통해 애플리케이션을 로컬로 실행할 때 local.settings.json 파일에서 애플리케이션 설정을 정의할 수 있습니다. 이 파일은 구성의 Values 속성에서 애플리케이션 설정을 정의합니다.

참고 항목

local.settings.json 파일은 로컬 개발에만 사용됩니다. Azure Portal을 사용하여 프로덕션에 대한 애플리케이션 설정을 구성합니다.

다음 샘플 local.settings.json에서는 DATABASE_CONNECTION_STRING에 대한 값을 추가하는 방법을 보여 줍니다.

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "node",
    "DATABASE_CONNECTION_STRING": "<YOUR_DATABASE_CONNECTION_STRING>"
  }
}

Settings defined in the Values property can be referenced from code as environment variables. In Node.js functions, for example, they're available in the process.env object.

const connectionString = process.env.DATABASE_CONNECTION_STRING;

The local.settings.json file isn't tracked by the GitHub repository because sensitive information, like database connection strings, are often included in the file. Since the local settings remain on your machine, you need to manually configure your settings in Azure.

Generally, configuring your settings is done infrequently, and isn't required with every build.

애플리케이션 설정 구성

Azure Portal 또는 Azure CLI를 통해 애플리케이션 설정을 구성할 수 있습니다.

Azure Portal 사용

Azure Portal은 애플리케이션 설정을 만들고 업데이트하고 삭제하기 위한 인터페이스를 제공합니다.

  1. Azure Portal로 이동합니다.

  2. 정적 웹앱을 엽니다.

  3. 사이드바에서 구성을 선택합니다.

  4. 애플리케이션 설정을 적용하려는 환경을 선택합니다. 환경마다 애플리케이션 설정을 구성할 수 있습니다. 끌어오기 요청을 만들면 스테이징 환경이 자동으로 만들어지고 끌어오기 요청을 병합할 때 프로덕션으로 승격됩니다.

  5. + 추가를 선택하여 새 앱 설정을 추가합니다. Azure Static Web Apps 구성 보기의 스크린샷

  6. 이름을 입력합니다.

  7. 확인을 선택합니다.

  8. 저장을 선택합니다.

Azure CLI 사용

az staticwebapp appsettings 명령을 사용하여 Azure에서 설정을 업데이트합니다.

터미널 또는 명령줄에서 다음 명령을 실행하여 message라는 설정을 Hello world 값으로 추가하거나 업데이트합니다. 자리 표시자 <YOUR_APP_ID>를 사용자의 값으로 바꿔야 합니다.

az staticwebapp appsettings set --name <YOUR_APP_ID> --setting-names "message=Hello world"

Tip

You can add or update multiple settings by passing multiple name-value pairs to --setting-names.

View application settings with the Azure CLI

In a terminal or command line, execute the following command. Make sure to replace the placeholder <YOUR_APP_ID> with your value.

az staticwebapp appsettings list --name <YOUR_APP_ID>

Delete application settings with the Azure CLI

In a terminal or command line, execute the following command to delete a setting named message. Make sure to replace the placeholder <YOUR_APP_ID> with your value.

az staticwebapp appsettings delete --name <YOUR_APP_ID> --setting-names "message"

Tip

Delete multiple settings by passing multiple setting names to --setting-names.