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: readme.md
+71-41Lines changed: 71 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,13 +14,24 @@ The Static Web Apps CLI, also known as SWA CLI, serves as a local development to
14
14
15
15
**Static Web Apps CLI is in preview.** If you have suggestions or you encounter issues, please report them or help us fix them. Your contributions are very much appreciated. 🙏
16
16
17
+
The CLI emulates commonly used capabilities of the Azure Static Web Apps cloud service. **Some differences are expected. Always deploy and test your apps in Azure to confirm behavior.**
18
+
17
19
## Quickstart
18
20
19
21
Using `npm` or `yarn`:
20
22
21
-
- Install the cli: `npm install -g @azure/static-web-apps-cli`
22
-
- Open a SWA app folder at the root (outside any /api or /app folders): `cd my-awesome-swa-app`
23
-
- Start the emulator: `swa start`
23
+
- Install the cli
24
+
```bash
25
+
npm install -g @azure/static-web-apps-cli
26
+
```
27
+
- Open a SWA app folder at the root (outside any /api or /app folders):
28
+
```bash
29
+
cd my-awesome-swa-app
30
+
```
31
+
- Start the emulator:
32
+
```bash
33
+
swa start
34
+
```
24
35
- Access your SWA app from `http://localhost:4280`
25
36
26
37
> Note: The cli can also be installed locally as a devDependency: `npm install -D @azure/static-web-apps-cli`
@@ -47,74 +58,89 @@ However, you can override this behavior. If the artifact folder of your static a
47
58
swa start ./my-dist
48
59
```
49
60
50
-
### Serve both the static app and API
51
-
52
-
If your project includes API functions, install [Azure Functions Core Tools](https://github.com/Azure/azure-functions-core-tools):
Run the CLI and provide the folder that contains the API backend (a valid Azure Functions App project):
59
-
60
-
```bash
61
-
swa start ./my-dist --api ./api-folder
62
-
```
63
-
64
61
### Serve from a dev server
65
62
66
63
When developing your frontend app locally, it's often useful to use the dev server that comes with your frontend framework's CLI to serve your app content. Using the framework CLI allows you to use built-in features like the livereload and HMR (hot module replacement).
67
64
68
65
To use SWA CLI with your local dev server, follow these two steps:
69
66
70
67
1. Start your local dev server (as usual). For example, if you are using Angular: `ng serve`
71
-
1. Run `swa start` with the URI provided by the dev server, in the following format:
68
+
1. In a separate terminal, run `swa start` with the URI provided by the dev server, in the following format:
When developing your backend locally, it's often useful to use the local API backend dev server to serve your API backend content. Using the backend server allows you to use built-in features like debugging and rich editor support.
88
+
If your project includes API functions, install [Azure Functions Core Tools](https://github.com/Azure/azure-functions-core-tools):
When developing your backend locally, sometimes it's useful to run Azure Functions Core Tools separately to serve your API. This allows you to use built-in features like debugging and rich editor support.
102
109
103
110
To use the CLI with your local API backend dev server, follow these two steps:
104
111
105
112
1. Start your API using Azure Functions Core Tools: `func host start` or start debugging in VS Code.
106
-
2. Run the SWA CLI with the `--api` flag and the URI of the local API server, in the following format:
113
+
2. In a separate terminal, run the SWA CLI with the `--api` flag and the URI of the local API server, in the following format:
114
+
```bash
115
+
swa start ./my-dist --api http://localhost:7071
116
+
```
117
+
118
+
## Use a configuration file (staticwebapp.config.json)
119
+
120
+
Azure Static Web Apps can be configured with an optional `staticwebapp.config.json` file. For more information, see [Configure Static Web Apps documentation](https://docs.microsoft.com/azure/static-web-apps/configuration).
121
+
122
+
If you are serving static files from a folder, the CLI will search this folder for `staticwebapp.config.json`.
107
123
108
124
```bash
109
-
swa start ./my-dist --api http://localhost:7071
125
+
# ./my-dist is searched for staticwebapp.config.json
126
+
swa start ./my-dist
110
127
```
111
128
112
-
### Serve with both local API backend and fontend app dev servers
129
+
If you are using a frontend dev server, the CLI will search the current directory for `staticwebapp.config.json`.
113
130
114
-
In a typical scenario, you're often developing both the front and backend of the app locally. To benefit from SWA features such as authentication and authorization, you can run the SWA CLI providing both dev server URIs:
131
+
```bash
132
+
# current working directory is searched for staticwebapp.config.json
133
+
swa start http://localhost:3000
134
+
```
135
+
136
+
To control where the CLI searches for `staticwebapp.config.json`, use `--swa-config-location`.
@@ -144,7 +170,7 @@ When requesting the Static Web Apps login endpoints (`http://localhost:4280/.aut
144
170
145
171
### Reading credentials
146
172
147
-
When requesting the `http://localhost:4280/.auth/me` endpoint, a `clientPrincipal` containing the fake information will be returned by the authentication API.
173
+
The frontend application can request the `http://localhost:4280/.auth/me` endpoint and a `clientPrincipal` containing the fake information will be returned by the authentication API.
148
174
149
175
Here is an example:
150
176
@@ -159,6 +185,10 @@ Here is an example:
159
185
}
160
186
```
161
187
188
+
The API functions can access user information using the `x-ms-client-principal` header.
189
+
190
+
See [Accessing user information](https://docs.microsoft.com/azure/static-web-apps/user-information) documentation for more details.
0 commit comments