Skip to content

Commit 02fdb90

Browse files
authored
fix: --api-devserver-url not working if --api-location not set (#523, #579) (#620)
* fix: --api-devserver-url not working if --api-location not set (#523, #579) * docs: fix documentation regarding --api-devserver-url usage (#579)
1 parent 7ecbae2 commit 02fdb90

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

docs/www/docs/cli/swa-start.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Here is a list of the default ports used by some popular dev servers:
5151
| [Next.js](https://nextjs.org/) | 3000 | `swa start http://localhost:3000` |
5252
| [React (Create React App)](https://reactjs.org/docs/create-a-new-react-app.html) | 3000 | `swa start http://localhost:3000` |
5353
| [Svelte (sirv-cli)](https://github.com/lukeed/sirv/tree/master/packages/sirv-cli/) | 5000 | `swa start http://localhost:5000` |
54-
| [Vue](https://github.com/vuejs/create-vue) | 3000 | `swa start http://localhost:3000` |
54+
| [Vue](https://github.com/vuejs/create-vue) | 3000 | `swa start http://localhost:3000` |
5555

5656
Instead of starting a dev server separately, you can provide the startup command to the CLI.
5757

@@ -94,10 +94,10 @@ When developing your backend locally, sometimes it's useful to run Azure Functio
9494
To use the CLI with your local API backend dev server, follow these two steps:
9595

9696
1. Start your API using Azure Functions Core Tools: `func host start` or start debugging in VS Code.
97-
2. In a separate terminal, run the SWA CLI with the `--api-location` flag and the URI of the local API server, in the following format:
97+
2. In a separate terminal, run the SWA CLI with the `--api-devserver-url` flag and the URI of the local API server, in the following format:
9898

9999
```bash
100-
swa start ./my-dist --api-location http://localhost:7071
100+
swa start ./my-dist --api-devserver-url http://localhost:7071
101101
```
102102

103103
## Options
@@ -108,7 +108,7 @@ Here are the options you can use with `swa start`:
108108
- `-i, --api-location <path>`: the folder containing the source code of the API application
109109
- `-O, --output-location <path>`: the folder containing the built source of the front-end application. The path is relative to `--app-location` (default: ".")
110110
- `-D, --app-devserver-url <url>`: connect to the app dev server at this URL instead of using output location
111-
- `-is, --api-devserver-url <url>`: connect to the api server at this URL instead of using output location
111+
- `-is, --api-devserver-url <url>`: connect to the api server at this URL instead of using api location
112112
- `-j, --api-port <apiPort>`: the API server port passed to `func start` (default: 7071)
113113
- `-q, --host <host>`: the host address to use for the CLI dev server (default: "localhost")
114114
- `-p, --port <port>`: the port value to use for the CLI dev server (default: 4280)
@@ -157,7 +157,7 @@ swa start http://localhost:3000 --run-build "npm start"
157157
Connect both front-end and the API to running development server
158158

159159
```bash
160-
swa start http://localhost:3000 --api-location http://localhost:7071
160+
swa start http://localhost:3000 --api-devserver-url http://localhost:7071
161161
```
162162

163163
## See Also

docs/www/docs/use/3-api-server.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ To use the SWA emulator services alongside the API server:
2929
func host start
3030
```
3131

32-
2. Start SWA CLI in a separate terminal and use the `--api-location` option to pass it the relevant local API Server URI. _For example:_
32+
2. Start SWA CLI in a separate terminal and use the `--api-devserver-url` option to pass it the relevant local API Server URI. _For example:_
3333

3434
```bash
35-
swa start ./my-dist --api-location http://localhost:7071
35+
swa start ./my-dist --api-devserver-url http://localhost:7071
3636
```
3737

3838
## 4.3 Start API Server Automatically

src/cli/commands/start.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ export default function registerCommand(program: Command) {
3535
.option("-a, --app-location <path>", "the folder containing the source code of the front-end application", DEFAULT_CONFIG.appLocation)
3636
.option("-i, --api-location <path>", "the folder containing the source code of the API application", DEFAULT_CONFIG.apiLocation)
3737
.option("-O, --output-location <path>", "the folder containing the built source of the front-end application", DEFAULT_CONFIG.outputLocation)
38-
.option("-D, --app-devserver-url <url>", "connect to the app dev server at this URL instead of using output location", DEFAULT_CONFIG.appDevserverUrl)
39-
.option("-is, --api-devserver-url <url>", "connect to the api server at this URL instead of using output location", DEFAULT_CONFIG.apiDevserverUrl)
38+
.option(
39+
"-D, --app-devserver-url <url>",
40+
"connect to the app dev server at this URL instead of using output location",
41+
DEFAULT_CONFIG.appDevserverUrl
42+
)
43+
.option("-is, --api-devserver-url <url>", "connect to the api server at this URL instead of using api location", DEFAULT_CONFIG.apiDevserverUrl)
4044
.option<number>("-j, --api-port <apiPort>", "the API server port passed to `func start`", parsePort, DEFAULT_CONFIG.apiPort)
4145
.option("-q, --host <host>", "the host address to use for the CLI dev server", DEFAULT_CONFIG.host)
4246
.option<number>("-p, --port <port>", "the port value to use for the CLI dev server", parsePort, DEFAULT_CONFIG.port)
@@ -107,7 +111,7 @@ Use a custom command to run framework development server at startup
107111
swa start http://localhost:3000 --run-build "npm start"
108112
109113
Connect both front-end and the API to running development server
110-
swa start http://localhost:3000 --api-location http://localhost:7071
114+
swa start http://localhost:3000 --api-devserver-url http://localhost:7071
111115
`
112116
);
113117
}
@@ -183,17 +187,16 @@ export async function start(options: SWACLIConfig) {
183187
logger.silly(` ${outputLocation}`);
184188
}
185189

186-
if (apiLocation) {
190+
if (apiDevserverUrl) {
191+
// TODO: properly refactor this after GA to send apiDevserverUrl to the server
192+
useApiDevServer = apiDevserverUrl;
193+
apiLocation = apiDevserverUrl;
194+
} else if (apiLocation) {
187195
// resolves to the absolute path of the apiLocation
188196
let resolvedApiLocation = path.resolve(apiLocation);
189197

190-
if (apiDevserverUrl) {
191-
// TODO: properly refactor this after GA to send apiDevserverUrl to the server
192-
useApiDevServer = apiDevserverUrl;
193-
apiLocation = apiDevserverUrl;
194-
}
195198
// make sure api folder exists
196-
else if (fs.existsSync(resolvedApiLocation)) {
199+
if (fs.existsSync(resolvedApiLocation)) {
197200
apiLocation = resolvedApiLocation;
198201
} else {
199202
logger.info(`Skipping API because folder "${resolvedApiLocation}" is missing`, "swa");

0 commit comments

Comments
 (0)