Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: --api-devserver-url not working if --api-location not set (#523, #579) #620

Merged
merged 2 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/www/docs/cli/swa-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Here is a list of the default ports used by some popular dev servers:
| [Next.js](https://nextjs.org/) | 3000 | `swa start http://localhost:3000` |
| [React (Create React App)](https://reactjs.org/docs/create-a-new-react-app.html) | 3000 | `swa start http://localhost:3000` |
| [Svelte (sirv-cli)](https://github.com/lukeed/sirv/tree/master/packages/sirv-cli/) | 5000 | `swa start http://localhost:5000` |
| [Vue](https://github.com/vuejs/create-vue) | 3000 | `swa start http://localhost:3000` |
| [Vue](https://github.com/vuejs/create-vue) | 3000 | `swa start http://localhost:3000` |

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

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

1. Start your API using Azure Functions Core Tools: `func host start` or start debugging in VS Code.
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:
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:

```bash
swa start ./my-dist --api-location http://localhost:7071
swa start ./my-dist --api-devserver-url http://localhost:7071
```

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

```bash
swa start http://localhost:3000 --api-location http://localhost:7071
swa start http://localhost:3000 --api-devserver-url http://localhost:7071
```

## See Also
Expand Down
4 changes: 2 additions & 2 deletions docs/www/docs/use/3-api-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ To use the SWA emulator services alongside the API server:
func host start
```

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:_
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:_

```bash
swa start ./my-dist --api-location http://localhost:7071
swa start ./my-dist --api-devserver-url http://localhost:7071
```

## 4.3 Start API Server Automatically
Expand Down
23 changes: 13 additions & 10 deletions src/cli/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ export default function registerCommand(program: Command) {
.option("-a, --app-location <path>", "the folder containing the source code of the front-end application", DEFAULT_CONFIG.appLocation)
.option("-i, --api-location <path>", "the folder containing the source code of the API application", DEFAULT_CONFIG.apiLocation)
.option("-O, --output-location <path>", "the folder containing the built source of the front-end application", DEFAULT_CONFIG.outputLocation)
.option("-D, --app-devserver-url <url>", "connect to the app dev server at this URL instead of using output location", DEFAULT_CONFIG.appDevserverUrl)
.option("-is, --api-devserver-url <url>", "connect to the api server at this URL instead of using output location", DEFAULT_CONFIG.apiDevserverUrl)
.option(
"-D, --app-devserver-url <url>",
"connect to the app dev server at this URL instead of using output location",
DEFAULT_CONFIG.appDevserverUrl
)
.option("-is, --api-devserver-url <url>", "connect to the api server at this URL instead of using api location", DEFAULT_CONFIG.apiDevserverUrl)
.option<number>("-j, --api-port <apiPort>", "the API server port passed to `func start`", parsePort, DEFAULT_CONFIG.apiPort)
.option("-q, --host <host>", "the host address to use for the CLI dev server", DEFAULT_CONFIG.host)
.option<number>("-p, --port <port>", "the port value to use for the CLI dev server", parsePort, DEFAULT_CONFIG.port)
Expand Down Expand Up @@ -107,7 +111,7 @@ Use a custom command to run framework development server at startup
swa start http://localhost:3000 --run-build "npm start"

Connect both front-end and the API to running development server
swa start http://localhost:3000 --api-location http://localhost:7071
swa start http://localhost:3000 --api-devserver-url http://localhost:7071
`
);
}
Expand Down Expand Up @@ -183,17 +187,16 @@ export async function start(options: SWACLIConfig) {
logger.silly(` ${outputLocation}`);
}

if (apiLocation) {
if (apiDevserverUrl) {
// TODO: properly refactor this after GA to send apiDevserverUrl to the server
useApiDevServer = apiDevserverUrl;
apiLocation = apiDevserverUrl;
} else if (apiLocation) {
// resolves to the absolute path of the apiLocation
let resolvedApiLocation = path.resolve(apiLocation);

if (apiDevserverUrl) {
// TODO: properly refactor this after GA to send apiDevserverUrl to the server
useApiDevServer = apiDevserverUrl;
apiLocation = apiDevserverUrl;
}
// make sure api folder exists
else if (fs.existsSync(resolvedApiLocation)) {
if (fs.existsSync(resolvedApiLocation)) {
apiLocation = resolvedApiLocation;
} else {
logger.info(`Skipping API because folder "${resolvedApiLocation}" is missing`, "swa");
Expand Down