Reputation: 1258
I have been trying to get Azure Static Web Apps CLI work with my blazor client app with an azure functions api. I can not debug locally and hit break points.
I have the most up to date version of the SWA CLI.
When I run
swa --version
I get back the result.
1.0.3
In the solution I have both the Api and the Client app set to start on debug
When I run it I get
Azure Functions Core Tools
Core Tools Version: 4.0.4865 Commit hash: N/A (64-bit)
Function Runtime Version: 4.12.2.19454
[2022-11-10T21:03:29.331Z] Found C:\github\xxx\Api\Api.csproj. Using for user secrets file configuration.
Functions:
Function1: [GET,POST] http://localhost:7129/api/Function1
WeatherForecast: [GET] http://localhost:7129/api/weather-forecast/{daysToForecast=5}
When I go to http://localhost:7129/api/weather-forecast/ it runs okay and hits my breakpoints When debingging the browser opens at https://localhost:5000 I browse to the razor page that calls
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("api/weather-forecast/5");
I get
''<' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.'
I expect this is because its returning a html page and is the reason that I should be using “Azure Static Web Apps CLI”
I have run the following in a new terminal widow and in the Developer PowerShell in visual studio 2022
Option 1
With the app running in debug from visual studio In a terminal window running from the root directory of the project
swa start http://localhost:5000
This give me
***********************************************************************
* WARNING: This emulator may not match the cloud environment exactly. *
* Always deploy and test your app in Azure. *
***********************************************************************
[swa]
[swa] Using dev server for static content:
[swa] https://localhost:5000/
[swa]
[swa] Azure Static Web Apps emulator started at http://localhost:4280. Press CTRL+C to exit.
[swa]
[swa]
I browse to http://localhost:4280 and then the terminal window does
[swa] GET https://localhost:5000//fetchdata (proxy)
[swa] node "C:\Users\xxx\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\dist\msha\server.js" exited with code 0
Option 2
With the app running in debug from visual studio In a terminal window running from the root directory of the project
swa init
Which give
Welcome to Azure Static Web Apps CLI (1.0.3)
? Choose a configuration name: » zzz
Detected configuration for your app:
- Framework(s): Blazor WASM, with API: .NET
- App location: Client
- Output location: bin\wwwroot
- API location: Api
- App build command: dotnet publish -c Release -o bin
- API build command: dotnet publish -c Release
- App dev server command: dotnet watch run
- App dev server URL: http://localhost:8000
? Are these settings correct? » (Y/n)
Then I entered
Swa start
Which gave
[api] Azure Functions Core Tools
[api] Core Tools Version: 4.0.4865 Commit hash: N/A (32-bit)
[api] Function Runtime Version: 4.12.2.19454
[api]
[api] [2022-11-10T21:25:12.343Z] Found C:\GitHub\xxx\Api\Api.csproj. Using for user secrets file configuration.
[api]
[api] Functions:
[api]
[api] Function1: [GET,POST] http://localhost:7071/api/Function1
[api]
[api] WeatherForecast: [GET] http://localhost:7071/api/weather-forecast/{daysToForecast=5}
[api]
[api] For detailed output, run func with --verbose flag.
[api] [2022-11-10T21:25:18.072Z] Host lock lease acquired by instance ID '0000000000000000000000003FF48B6B'.
✖ Waiting for http://localhost:8000 to be ready
[swa] ✖ Could not connect to "http://localhost:8000". Is the server up and running?
[swa] node "C:\Users\xxx\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\dist\msha\server.js" exited with code 0
--> Sending SIGTERM to other processes..
[api] cd "C:\GitHub\zzz\Api" && C:\Users\Ashley\.swa\core-tools\v4\func start --cors "*" --port 7071 exited with code 1
--> Sending SIGTERM to other processes..
[run] cd "C:\GitHub\zzz\Client" && dotnet watch run exited with code 1
✖ SWA emulator stoped because the --run command exited with code 1.
So gave up on that avenue
Option 3
With the app running in debug from visual studio In a terminal window running from the root directory of the project
swa start https://localhost:5000 --api-location http://localhost:7129
which gave
Welcome to Azure Static Web Apps CLI (1.0.3)
***********************************************************************
* WARNING: This emulator may not match the cloud environment exactly. *
* Always deploy and test your app in Azure. *
***********************************************************************
[swa]
[swa] Using dev server for static content:
[swa] https://localhost:5000
[swa]
[swa] Using dev server for API:
[swa] http://localhost:7129
[swa]
[swa] Azure Static Web Apps emulator started at http://localhost:4280. Press CTRL+C to exit.
[swa]
[swa]
I browse to http://localhost:4280/ And the page is This site can’t be reached And the terminal says
[swa] GET https://localhost:5000/fetchdata (proxy)
[swa] node "C:\Users\xxx\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\dist\msha\server.js" exited with code 0
I have tried the most up to date version of node.js and a few older ones, to rule that out being the issue.
I can not work out how to get the front end and api to work together with this tool, with the guide I am working through I have the feeling I will need to get them working for things later on.
Update
It seems to work if you use the http port number instead of the https port number.... not sure what that will mean going forward.
Upvotes: 3
Views: 1404