Skip to content

Commit ef93066

Browse files
Merge pull request #261365 from craigshoemaker/swa/cli-migration
[Static Web Apps] SWA CLI Article Migration (3 new articles, 2 updates)
2 parents fbc95d9 + f1f055f commit ef93066

9 files changed

+403
-120
lines changed

articles/static-web-apps/TOC.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,20 @@
211211
href: /rest/api/appservice/static-sites
212212
- name: SWA CLI
213213
items:
214-
- name: Summary
215-
href: static-web-apps-cli.yml
214+
- name: Overview
215+
href: static-web-apps-cli-overview.md
216+
- name: Install
217+
href: static-web-apps-cli-install.md
218+
- name: Start the emulator
219+
href: static-web-apps-cli-emulator.md
220+
- name: Start the API server
221+
href: static-web-apps-cli-api-server.md
222+
- name: Deploy to Azure
223+
href: static-web-apps-cli-deploy.md
216224
- name: Configure SWA CLI
217225
href: static-web-apps-cli-configuration.md
218-
- name: Deploy static web app with SWA CLI
219-
href: static-web-apps-cli-deploy.md
226+
- name: API Reference
227+
href: static-web-apps-cli.yml
220228
- name: Samples & FAQs
221229
items:
222230
- name: Samples

articles/static-web-apps/local-development.md

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services: static-web-apps
55
author: craigshoemaker
66
ms.service: static-web-apps
77
ms.topic: how-to
8-
ms.date: 08/09/2022
8+
ms.date: 02/05/2024
99
ms.author: cshoe
1010
ms.custom:
1111
---
@@ -21,7 +21,7 @@ When published to the cloud, an Azure Static Web Apps site links together many s
2121

2222
These services must communicate with each other, and Azure Static Web Apps handles this integration for you in the cloud.
2323

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.
2525

2626
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:
2727

@@ -34,34 +34,9 @@ To provide a similar experience as to what you get in Azure, the [Azure Static W
3434
> [!NOTE]
3535
> 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`.
3636
37-
## How it works
37+
[!INCLUDE [Local development overview](../../includes/static-web-apps-local-dev-overview.md)]
3838

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:
57-
58-
```console
59-
swa start http://localhost:<DEV-SERVER-PORT-NUMBER> --api-location http://localhost:7071
60-
```
61-
62-
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.
6540

6641
## Prerequisites
6742

@@ -108,7 +83,7 @@ Open a terminal to the root folder of your existing Azure Static Web Apps site.
10883
|--|--|--|
10984
| Serve a specific folder | `swa start ./<OUTPUT_FOLDER_NAME>` | Replace `<OUTPUT_FOLDER_NAME>` with the name of your output folder. |
11085
| 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. |
11287
| 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. |
11388

11489
## Authorization and authentication emulation
@@ -135,7 +110,7 @@ Once logged in:
135110

136111
- You can use the `/.auth/me` endpoint, or a function endpoint to retrieve the user's [client principal](./user-information.md).
137112

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.
139114

140115
## Debugging
141116

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: API server Azure Static Web Apps CLI
3+
description: API server Azure Static Web Apps CLI
4+
services: static-web-apps
5+
author: craigshoemaker
6+
ms.service: static-web-apps
7+
ms.topic: conceptual
8+
ms.date: 02/02/2024
9+
ms.author: cshoe
10+
---
11+
12+
# 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.
31+
32+
For example:
33+
34+
```bash
35+
swa start ./my-dist --api-devserver-url http://localhost:7071
36+
```
37+
38+
## Automatic start
39+
40+
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
49+
50+
```bash
51+
swa start http://localhost:3000 --api-location ./api
52+
```
53+
54+
## Next steps
55+
56+
> [!div class="nextstepaction"]
57+
> [Deploy to Azure](static-web-apps-cli-deploy.md)

articles/static-web-apps/static-web-apps-cli-configuration.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services: static-web-apps
55
author: craigshoemaker
66
ms.service: static-web-apps
77
ms.topic: conceptual
8-
ms.date: 09/30/2022
8+
ms.date: 02/02/2024
99
ms.author: cshoe
1010
---
1111

@@ -22,9 +22,12 @@ The Azure Static Web Apps (SWA) CLI gets configuration information for your stat
2222
The configuration file can contain multiple configurations, each identified by a unique configuration name.
2323

2424
- 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.
2625

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.
2831

2932
```json
3033
{
@@ -39,29 +42,31 @@ The configuration file can contain multiple configurations, each identified by a
3942
}
4043
```
4144

45+
When you only have one configuration section, as shown by this example, then the `swa start` command automatically uses these values.
46+
4247
## Initialize a configuration file
4348

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.
4550

4651
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.
4752

4853
```azstatic-cli
4954
swa --config <PATH>
5055
```
5156

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.
5358

5459
```azstatic-cli
55-
swa --config-name
60+
swa --<CONFIG_NAME>
5661
```
5762

5863
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.
5964

6065
## View configuration
6166

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.
6368

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.
6570

6671
```azstatic-cli
6772
swa --print-config
@@ -105,4 +110,4 @@ Running `swa --print-config` provide's the current configuration defaults.
105110
106111
## Validate configuration
107112

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

Comments
 (0)