Skip to content

Commit 6c487f9

Browse files
authored
docs: update readme and help (#215)
1 parent 16990e8 commit 6c487f9

2 files changed

Lines changed: 79 additions & 49 deletions

File tree

readme.md

Lines changed: 71 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@ The Static Web Apps CLI, also known as SWA CLI, serves as a local development to
1414

1515
**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. 🙏
1616

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+
1719
## Quickstart
1820

1921
Using `npm` or `yarn`:
2022

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+
```
2435
- Access your SWA app from `http://localhost:4280`
2536

2637
> 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
4758
swa start ./my-dist
4859
```
4960

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):
53-
54-
```bash
55-
npm install -g azure-functions-core-tools@3 --unsafe-perm true
56-
```
57-
58-
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-
6461
### Serve from a dev server
6562

6663
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).
6764

6865
To use SWA CLI with your local dev server, follow these two steps:
6966

7067
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:
69+
```bash
70+
swa start http://<APP_DEV_SERVER_HOST>:<APP_DEV_SERVER_PORT>
71+
```
7272

73-
```bash
74-
swa start http://<APP_DEV_SERVER_HOST>:<APP_DEV_SERVER_PORT>
75-
```
76-
77-
Here is a list of the default ports used by popular dev servers:
73+
Here is a list of the default ports used by some popular dev servers:
7874

7975
| Tool | Port | Command |
8076
| ---------------------------------------------------------------------------------- | ---- | --------------------------------- |
8177
| [Angular](https://angular.io/cli) | 4200 | `swa start http://localhost:4200` |
8278
| [Vue](https://cli.vuejs.org/) | 8080 | `swa start http://localhost:8080` |
83-
| [Vite](https://github.com/vitejs/vite/) | 3000 | `swa start http://localhost:3000` |
84-
| [Create React App](https://reactjs.org/docs/create-a-new-react-app.html) | 3000 | `swa start http://localhost:3000` |
79+
| [React (Create React App)](https://reactjs.org/docs/create-a-new-react-app.html) | 3000 | `swa start http://localhost:3000` |
8580
| [Blazor WebAssembly](https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor) | 5000 | `swa start http://localhost:5000` |
86-
| [Webpack Dev Server](https://github.com/webpack/webpack-dev-server) | 8080 | `swa start http://localhost:8080` |
87-
| [Parcel](https://parceljs.org/cli.html) | 1234 | `swa start http://localhost:1234` |
88-
| [Stencil](https://stenciljs.com/docs/dev-server) | 3333 | `swa start http://localhost:3333` |
8981
| [Hugo](https://gohugo.io/commands/hugo_server/) | 1313 | `swa start http://localhost:1313` |
90-
| [Elm (live server)](https://github.com/wking-io/elm-live/) | 8000 | `swa start http://localhost:8000` |
91-
| [Ionic](https://ionicframework.com/docs/cli/commands/serve/) | 8100 | `swa start http://localhost:8100` |
9282
| [Svelte (sirv-cli)](https://github.com/lukeed/sirv/tree/master/packages/sirv-cli/) | 5000 | `swa start http://localhost:5000` |
93-
| [Sapper](https://sapper.svelte.dev/) | 3000 | `swa start http://localhost:3000` |
94-
| [Scully.io](https://scully.io/) | 1668 | `swa start http://localhost:1668` |
9583
| [Gatsby](https://www.gatsbyjs.com/docs/gatsby-cli/) | 8000 | `swa start http://localhost:8000` |
96-
| [Nuxt.js](https://nuxtjs.org/) | 3000 | `swa start http://localhost:3000` |
9784
| [Next.js](https://nextjs.org/) | 3000 | `swa start http://localhost:3000` |
9885

99-
### Serve with a local API backend dev server
86+
### Serve both the static app and API
10087

101-
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):
89+
90+
```bash
91+
npm install -g azure-functions-core-tools@3 --unsafe-perm true
92+
```
93+
94+
#### Start API server automatically
95+
96+
Run the CLI and provide the folder that contains the API backend (a valid Azure Functions App project):
97+
98+
```bash
99+
# static content plus API
100+
swa start ./my-dist --api ./api-folder
101+
102+
# frontend dev server plus API
103+
swa start http://localhost:3000 --api ./api-folder
104+
```
105+
106+
#### Start API server manually
107+
108+
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.
102109

103110
To use the CLI with your local API backend dev server, follow these two steps:
104111

105112
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`.
107123

108124
```bash
109-
swa start ./my-dist --api http://localhost:7071
125+
# ./my-dist is searched for staticwebapp.config.json
126+
swa start ./my-dist
110127
```
111128

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`.
113130

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`.
115137

116138
```bash
117-
swa start http://<APP_DEV_SERVER> --api=http://localhost:7071
139+
# static files
140+
swa start ./my-dist --swa-config-location ./my-app-source
141+
142+
# frontend dev server
143+
swa start http://localhost:3000 --swa-config-location ./my-app-source
118144
```
119145

120146
## Configuration
@@ -144,7 +170,7 @@ When requesting the Static Web Apps login endpoints (`http://localhost:4280/.aut
144170

145171
### Reading credentials
146172

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

149175
Here is an example:
150176

@@ -159,6 +185,10 @@ Here is an example:
159185
}
160186
```
161187

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.
191+
162192
## High-level architecture
163193

164194
![swa cli architecture](./docs/swa-cli-architecture.png)

src/cli/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exports.run = async function () {
1313
// SWA config
1414
.option("--verbose [prefix]", "enable verbose output. Values are: silly,info,log,silent", DEFAULT_CONFIG.verbose)
1515

16-
.addHelpText("after", "\nDocumentation:\n https://aka.ms/swa/cli-local-development");
16+
.addHelpText("after", "\nDocumentation:\n https://aka.ms/swa/cli-local-development\n");
1717

1818
program
1919
.command("start [context]")
@@ -26,13 +26,10 @@ exports.run = async function () {
2626
DEFAULT_CONFIG.outputLocation
2727
)
2828
.option("--api, --api-location <apiLocation>", "set the API folder or Azure Functions emulator address", DEFAULT_CONFIG.apiLocation)
29-
.addOption(
30-
new Option(
31-
"--swa-config-location <swaConfigLocation>",
32-
"set the directory location where the staticwebapp.config.json file is found. This location is relative to the root of the project"
33-
)
34-
.default(DEFAULT_CONFIG.swaConfigLocation)
35-
.hideHelp()
29+
.option(
30+
"--swa-config-location <swaConfigLocation>",
31+
"set the directory where the staticwebapp.config.json file is found",
32+
DEFAULT_CONFIG.swaConfigLocation
3633
)
3734

3835
// CLI config
@@ -79,6 +76,9 @@ Examples:
7976
Use an already running framework development server
8077
swa start http://localhost:3000
8178
79+
Use staticwebapp.config.json file in a specific location
80+
swa start http://localhost:3000 --swa-config-location ./app-source
81+
8282
Serve static content and run an API from another folder
8383
swa start ./output-folder --api ./api
8484
`

0 commit comments

Comments
 (0)