You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/static-web-apps/local-development.md
+6-31Lines changed: 6 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ services: static-web-apps
5
5
author: craigshoemaker
6
6
ms.service: static-web-apps
7
7
ms.topic: how-to
8
-
ms.date: 08/09/2022
8
+
ms.date: 02/05/2024
9
9
ms.author: cshoe
10
10
ms.custom:
11
11
---
@@ -21,7 +21,7 @@ When published to the cloud, an Azure Static Web Apps site links together many s
21
21
22
22
These services must communicate with each other, and Azure Static Web Apps handles this integration for you in the cloud.
23
23
24
-
Running locally, however, these services aren't automatically tied together.
24
+
However, when you run your application locally these services aren't automatically tied together.
25
25
26
26
To provide a similar experience as to what you get in Azure, the [Azure Static Web Apps CLI](https://github.com/Azure/static-web-apps-cli) provides the following services:
27
27
@@ -34,34 +34,9 @@ To provide a similar experience as to what you get in Azure, the [Azure Static W
34
34
> [!NOTE]
35
35
> Often sites built with a front-end framework require a proxy configuration setting to correctly handle requests under the `api` route. When using the Azure Static Web Apps CLI the proxy location value is `/api`, and without the CLI the value is `http://localhost:7071/api`.
36
36
37
-
## How it works
37
+
[!INCLUDE [Local development overview](../../includes/static-web-apps-local-dev-overview.md)]
38
38
39
-
The following chart shows how requests are handled locally.
40
-
41
-
:::image type="content" source="media/local-development/cli-conceptual.png" alt-text="Azure Static Web App CLI request and response flow":::
42
-
43
-
> [!IMPORTANT]
44
-
> Go to `http://localhost:4280` to access the application served by the CLI.
45
-
46
-
-**Requests** made to port `4280` are forwarded to the appropriate server depending on the type of request.
47
-
48
-
-**Static content** requests, such as HTML or CSS, are either handled by the internal CLI static content server, or by the front-end framework server for debugging.
49
-
50
-
-**Authentication and authorization** requests are handled by an emulator, which provides a fake identity profile to your app.
51
-
52
-
-**Functions Core Tools runtime**<sup>1</sup> handles requests to the site's API.
53
-
54
-
-**Responses** from all services are returned to the browser as if they were all a single application.
55
-
56
-
The following article details the steps for running a node-based application, but the process is the same for any language or environment. Once you start the UI and the Azure Functions API apps independently, then start the Static Web Apps CLI and point it to the running apps using the following command:
Optionally, if you use the `swa init` command, the Static Web Apps CLI looks at your application code and build a _swa-cli.config.json_ configuration file for the CLI. When you use the _swa-cli.config.json_ file, you can run `swa start` to launch your application locally.
63
-
64
-
<sup>1</sup> The Azure Functions Core Tools are automatically installed by the CLI if they aren't already on your system.
39
+
The following article details the steps for running a node-based application, but the process is the same for any language or environment.
65
40
66
41
## Prerequisites
67
42
@@ -108,7 +83,7 @@ Open a terminal to the root folder of your existing Azure Static Web Apps site.
108
83
|--|--|--|
109
84
| Serve a specific folder | `swa start ./<OUTPUT_FOLDER_NAME>` | Replace `<OUTPUT_FOLDER_NAME>` with the name of your output folder. |
110
85
| Use a running framework development server | `swa start http://localhost:3000` | This command works when you have an instance of your application running under port `3000`. Update the port number if your configuration is different. |
111
-
| Start a Functions app in a folder | `swa start ./<OUTPUT_FOLDER_NAME> --api-location ./api` | Replace `<OUTPUT_FOLDER_NAME>` with the name of your output folder. This command expects your application's API to have files in the _api_ folder. Update this value if your configuration is different. |
86
+
| Start a Functions app in a folder | `swa start ./<OUTPUT_FOLDER_NAME> --api-location ./api` | Replace `<OUTPUT_FOLDER_NAME>` with the name of your output folder. This command expects your application's API to have files in the `api` folder. Update this value if your configuration is different. |
112
87
| Use a running Functions app | `swa start ./<OUTPUT_FOLDER_NAME> --api-location http://localhost:7071` | Replace `<OUTPUT_FOLDER_NAME>` with the name of your output folder. This command expects your Azure Functions application to be available through port `7071`. Update the port number if your configuration is different. |
113
88
114
89
## Authorization and authentication emulation
@@ -135,7 +110,7 @@ Once logged in:
135
110
136
111
- You can use the `/.auth/me` endpoint, or a function endpoint to retrieve the user's [client principal](./user-information.md).
137
112
138
-
- Navigating to `/.auth/logout` clears the client principal and logs out the mock user.
113
+
- Navigating to `/.auth/logout` clears the client principal and signs out the mock user.
# Start the API server with the Azure Static Web App CLI
13
+
14
+
In Azure Static Web Apps, you can use the [integrated managed Functions](/azure/static-web-apps/apis-functions) to add API endpoints to your application. You can run an Azure Functions app locally using [Azure Functions core tools CLI](/azure/azure-functions/functions-run-local). The core tools CLI gives you the opportunity to run and debug your API endpoints locally.
15
+
16
+
You can start the core tools manually or automatically.
17
+
18
+
## Manual start
19
+
20
+
To use the SWA CLI emulator alongside the API server:
21
+
22
+
1. Start API server using the Azure Functions core tools CLI or the [Visual Studio Code Extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions).
23
+
24
+
Copy the URL of the local API server, once the core tools are running.
25
+
26
+
```bash
27
+
func host start
28
+
```
29
+
30
+
1. In a separate terminal, start the SWA CLI using the `--api-devserver-url` option to pass it the local API Server URI.
To set up an automatic start, you first need to have an Azure Functions application project located in an `api` folder in your local development environment.
41
+
42
+
1. Launch the API server alongside the SWA emulator
43
+
44
+
```bash
45
+
swa start ./my-dist --api-location ./api
46
+
```
47
+
48
+
1. Combine the launch with usage of a running dev server
Copy file name to clipboardExpand all lines: articles/static-web-apps/static-web-apps-cli-configuration.md
+14-9Lines changed: 14 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ services: static-web-apps
5
5
author: craigshoemaker
6
6
ms.service: static-web-apps
7
7
ms.topic: conceptual
8
-
ms.date: 09/30/2022
8
+
ms.date: 02/02/2024
9
9
ms.author: cshoe
10
10
---
11
11
@@ -22,9 +22,12 @@ The Azure Static Web Apps (SWA) CLI gets configuration information for your stat
22
22
The configuration file can contain multiple configurations, each identified by a unique configuration name.
23
23
24
24
- If only a single configuration is present in the *swa-cli.config.json* file, `swa start` uses it by default.
25
-
- If options are loaded from a config file, then command line options are ignored. For example, if you run `swa start app --ssl`, the `ssl=true` option is not be picked up by the CLI.
26
25
27
-
## Configuration file example
26
+
- If options are loaded from a config file, then command line options are ignored.
27
+
28
+
## Example configuration file
29
+
30
+
The following code snippet shows the configuration file's shape.
28
31
29
32
```json
30
33
{
@@ -39,29 +42,31 @@ The configuration file can contain multiple configurations, each identified by a
39
42
}
40
43
```
41
44
45
+
When you only have one configuration section, as shown by this example, then the `swa start` command automatically uses these values.
46
+
42
47
## Initialize a configuration file
43
48
44
-
Use `swa init` to kickstart the workflow to create a configuration file for a new or existing project. If the project exists,`swa init` tries to guess the configuration settings for you.
49
+
You can initialize your configuration file with the `swa init` command. If you run the command against an existing project, then`swa init` tries to guess the configuration settings for you.
45
50
46
51
By default, the process creates these settings in a *swa-cli.config.json* in the current working directory of your project. This directory is the default file name and location used by `swa` when searching for project configuration values.
47
52
48
53
```azstatic-cli
49
54
swa --config <PATH>
50
55
```
51
56
52
-
If the file contains only one named configuration, then it is used by default. If multiple configurations are defined, you need to specify the one to use as an option.
57
+
If the file contains only one named configuration, then that configuration is used by default. If multiple configurations are defined, then you pass the desired configuration name in as an option.
53
58
54
59
```azstatic-cli
55
-
swa --config-name
60
+
swa --<CONFIG_NAME>
56
61
```
57
62
58
63
When the configuration file option is used, the settings are stored in JSON format. Once created, you can manually edit the file to update settings or use `swa init` to make updates.
59
64
60
65
## View configuration
61
66
62
-
The Static Webs CLI provides a `--print-config` option so you can determine resolved options for your current setup.
67
+
The Static Webs CLI provides a `--print-config` option so you can review your current configuration.
63
68
64
-
Here is an example of what that output looks like when run on a new project with default settings.
69
+
Here's an example of what that output looks like when run on a new project with default settings.
65
70
66
71
```azstatic-cli
67
72
swa --print-config
@@ -105,4 +110,4 @@ Running `swa --print-config` provide's the current configuration defaults.
105
110
106
111
## Validate configuration
107
112
108
-
The swa-cli.config.json file can be validated against the following schema: https://aka.ms/azure/static-web-apps-cli/schema
113
+
You can validate the *swa-cli.config.json* file against the following schema: https://aka.ms/azure/static-web-apps-cli/schema
0 commit comments