Skip to content

Commit 294fcbf

Browse files
authored
Merge pull request #207388 from craigshoemaker/swa/local
[Static Web Apps] Local development
2 parents 36167c2 + 71a60df commit 294fcbf

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

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

Lines changed: 23 additions & 14 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: 01/14/2022
8+
ms.date: 08/09/2022
99
ms.author: cshoe
1010
ms.custom: devx-track-js
1111
---
@@ -49,7 +49,7 @@ The following chart shows how requests are handled locally.
4949

5050
- **Authentication and authorization** requests are handled by an emulator, which provides a fake identity profile to your app.
5151

52-
- **Functions Core Tools runtime** handles requests to the site's API.
52+
- **Functions Core Tools runtime**<sup>1</sup> handles requests to the site's API.
5353

5454
- **Responses** from all services are returned to the browser as if they were all a single application.
5555

@@ -59,12 +59,15 @@ The following article details the steps for running a node-based application, bu
5959
swa start http://localhost:<DEV-SERVER-PORT-NUMBER> --api-location http://localhost:7071
6060
```
6161

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.
65+
6266
## Prerequisites
6367

6468
- **Existing Azure Static Web Apps site**: If you don't have one, begin with the [vanilla-api](https://github.com/staticwebdev/vanilla-api/generate?return_to=/staticwebdev/vanilla-api/generate) starter app.
6569
- **[Node.js](https://nodejs.org) with npm**: Run the [Node.js LTS](https://nodejs.org) version, which includes access to [npm](https://www.npmjs.com/).
6670
- **[Visual Studio Code](https://code.visualstudio.com/)**: Used for debugging the API application, but not required for the CLI.
67-
- **[Azure Functions Core Tools](https://github.com/Azure/azure-functions-core-tools#installing)**: Required to run the API locally.
6871

6972
## Get started
7073

@@ -73,14 +76,20 @@ Open a terminal to the root folder of your existing Azure Static Web Apps site.
7376
1. Install the CLI.
7477

7578
```console
76-
npm install -g @azure/static-web-apps-cli azure-functions-core-tools
79+
npm install @azure/static-web-apps-cli
7780
```
7881

7982
1. Build your app if required by your application.
8083

8184
Run `npm run build`, or the equivalent command for your project.
8285

83-
1. Change into the output directory for your app. Output folders are often named _build_ or something similar.
86+
1. Initialize the repository for the CLI.
87+
88+
```console
89+
swa init
90+
```
91+
92+
Answer the questions posed by the CLI to verify your configuration settings are correct.
8493

8594
1. Start the CLI.
8695

@@ -92,12 +101,12 @@ Open a terminal to the root folder of your existing Azure Static Web Apps site.
92101

93102
### Other ways to start the CLI
94103

95-
| Description | Command |
96-
|--- | --- |
97-
| Serve a specific folder | `swa start ./output-folder` |
98-
| Use a running framework development server | `swa start http://localhost:3000` |
99-
| Start a Functions app in a folder | `swa start ./output-folder --api-location ./api` |
100-
| Use a running Functions app | `swa start ./output-folder --api-location http://localhost:7071` |
104+
| Description | Command | Comments |
105+
|--|--|--|
106+
| Serve a specific folder | `swa start ./<OUTPUT_FOLDER_NAME>` | Replace `<OUTPUT_FOLDER_NAME>` with the name of your output folder. |
107+
| 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. |
108+
| 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. |
109+
| 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. |
101110

102111
## Authorization and authentication emulation
103112

@@ -117,6 +126,7 @@ The emulator provides a page allowing you to provide the following [client princ
117126
| **Username** | The account name associated with the security provider. This value appears as the `userDetails` property in the client principal and is autogenerated if you don't provide a value. |
118127
| **User ID** | Value autogenerated by the CLI. |
119128
| **Roles** | A list of role names, where each name is on a new line. |
129+
| **Claims** | A list of [user claims](user-information.md#client-principal-data), where each name is on a new line. |
120130

121131
Once logged in:
122132

@@ -136,12 +146,11 @@ The following steps show you a common scenario that uses development servers for
136146

137147
1. Start the Static Web Apps CLI using the following command.
138148

139-
140149
```console
141-
swa start http://localhost:<DEV-SERVER-PORT-NUMBER> --api-location http://localhost:7071
150+
swa start http://localhost:<DEV-SERVER-PORT-NUMBER> --appDevserverUrl http://localhost:7071
142151
```
143152

144-
Replace `<DEV-SERVER-PORT-NUMBER>` with the development server's port number.
153+
Replace `<DEV_SERVER_PORT_NUMBER>` with the development server's port number.
145154

146155
The following screenshots show the terminals for a typical debugging scenario:
147156

25.6 KB
Loading
-8.44 KB
Loading

0 commit comments

Comments
 (0)