-
Notifications
You must be signed in to change notification settings - Fork 21.8k
Expand file tree
/
Copy pathapplication-settings.yml
More file actions
137 lines (101 loc) · 6.05 KB
/
application-settings.yml
File metadata and controls
137 lines (101 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
### YamlMime:HowTo
metadata:
title: Configure application settings for Azure Static Web Apps
description: Learn how to configure application settings for Azure Static Web Apps.
author: cjk7989
ms.author: jikunchen
ms.date: 01/10/2023
ms.service: azure-static-web-apps
ms.topic: how-to
ms.custom:
- sfi-ropc-nochange
- ge-structured-content-pilot
- engagement-fy23
title: |
Configure application settings for Azure Static Web Apps
introduction: |
Application settings hold configuration values that may change, such as database connection strings. Adding application settings allows you to modify the configuration input to your app, without having to change application code.
Application settings:
- Are available as environment variables to the backend API of a static web app
- Can be used to store secrets used in [authentication configuration](key-vault-secrets.md)
- Are encrypted at rest
- Are copied to [staging](review-publish-pull-requests.md) and production environments
- May only be alphanumeric characters, `.`, and `_`
The application settings described in this article only apply to the backend API of an Azure Static Web App.
To configure environment variables required to build your frontend web application, see [Build configuration](build-configuration.md#environment-variables).
prerequisites:
summary: |
- An Azure Static Web Apps application
- [Azure CLI](/cli/azure/install-azure-cli)-required if you are using the command line
procedureSection:
- title: |
Configure API application settings for local development
summary: |
APIs in Azure Static Web Apps are powered by Azure Functions, which allows you to define application settings in the _local.settings.json_ file when you run the application locally. This file defines application settings in the `Values` property of the configuration.
> [!NOTE]
> The _local.settings.json_ file is only used for local development. Use the [Azure portal](#configure-application-settings) to configure application settings for production.
The following sample _local.settings.json_ shows how to add a value for the `DATABASE_CONNECTION_STRING`.
code: |
```json
{
"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.
```js
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.
- title: |
Configure application settings
summary: |
You can configure application settings via the [Azure portal](https://portal.azure.com) or with the [Azure CLI](#use-the-azure-cli).
> [!IMPORTANT]
> The application settings described in this article only apply to the backend API of an Azure Static Web App.
>
> To configure environment variables required to build your frontend web application, see [Build configuration](build-configuration.md#environment-variables).
### Use the Azure portal
The Azure portal provides an interface for creating, updating and deleting application settings.
1. Go to the [Azure portal](https://portal.azure.com).
1. Open your static web app.
1. Under the *Settings* section, select **Environment variables**.
1. Select the environment to which you want to create environment variables. You can create variables per environment. When you create a pull request, staging environments are automatically created, and then promoted into production when you merge the pull request.
1. Select **+ Add** to add a new environment variable.
1. Enter your values in the *Name* and *Value* boxes.
1. Select **Apply**.
1. Select **Apply** again to save your changes.
### Use the Azure CLI
Use the `az staticwebapp appsettings` command to update your settings in Azure.
In a terminal or command line, execute the following command to add or update a setting named `message` with a value of `Hello world`. Make sure to replace the placeholder `<YOUR_APP_ID>` with your value.
code: |
```azurecli
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.
```azurecli
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.
```azurecli
az staticwebapp appsettings delete --name <YOUR_APP_ID> --setting-names "message"
```
> [!TIP]
> Delete multiple settings by passing multiple setting names to `--setting-names`.
relatedContent:
- text: Define configuration for Azure Static Web Apps in the _staticwebapp.config.json_ file
url: configuration.md
- text: Override defaults with custom registration
url: authentication-custom.md
- text: Define settings that control the build process
url: ./build-configuration.md
#- [API overview](apis-overview.md)