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

swa start doesn't run both api and static site together #599

Closed
peterfearn opened this issue Nov 8, 2022 · 13 comments
Closed

swa start doesn't run both api and static site together #599

peterfearn opened this issue Nov 8, 2022 · 13 comments
Assignees
Labels
status: duplicate This issue or pull request already exists status: investigating The team is investigating the issues

Comments

@peterfearn
Copy link

peterfearn commented Nov 8, 2022

Describe the bug
I cannot start the static page and api at the same time using one command.

To Reproduce

  1. Follow the tutorial here https://learn.microsoft.com/en-us/azure/static-web-apps/getting-started?tabs=vanilla-javascript
  2. Get to the running locally step https://learn.microsoft.com/en-us/azure/static-web-apps/add-api?tabs=vanilla-javascript#start-the-cli
  3. run the command swa start src --api-location api

Expected behaviour
I expect to be able to browse to http://localhost:4280 and make a GET api call to http://localhost:7071/api/message but can only access the api, the site at 4280 is not running.

If I run the command swa start src then I get the http://localhost:4280 site running, but obviously not the API

Output (verbose)
log from running swa start src --api-location api --verbose=silly

Welcome to Azure Static Web Apps CLI (1.0.3)

Getting config file options from swa-cli.config.json...
Config file does not exist at C:\<redacted>\spa-vanilla\swa-cli.config.json
***********************************************************************
* WARNING: This emulator may not match the cloud environment exactly. *
* Always deploy and test your app in Azure.                           *
***********************************************************************

Checking if localhost:4280 is accepting TCP connections...
Port 4280 is available. Use it.
Resolved port number: 4280
Resolving outputLocation=src full path...
Resolved outputLocation:
  C:\<redacted>\spa-vanilla\src
Trying to read workflow config with values:
 - appLocation: C:\<redacted>\spa-vanilla
 - outputLocation: C:\<redacted>\spa-vanilla\src
 - apiLocation: C:\<redacted>\spa-vanilla\api
Found a SWA workflow file: C:\<redacted>\spa-vanilla\.github\workflows\azure-static-web-apps-thankful-island-0c2e35803.yml
 - app_build_command: <undefined>
 - api_build_command: <undefined>
 - app_location: /src
 - output_location: /src
 - api_location: api
Validating user workflow config (BEFORE):
 - appLocation: C:\<redacted>\spa-vanilla
 - outputLocation: C:\<redacted>\spa-vanilla\src
 - apiLocation: C:\<redacted>\spa-vanilla\api
Validating user workflow config (AFTER):
 - appLocation: C:\<redacted>\spa-vanilla
 - apiLocation: C:\<redacted>\spa-vanilla\api
 - outputLocation: C:\<redacted>\spa-vanilla\src
Workflow configuration:
- config:
  - appBuildCommand: <undefined>
  - apiBuildCommand: <undefined>
  - appLocation: C:\<redacted>\spa-vanilla
  - apiLocation: C:\<redacted>\spa-vanilla\api
  - outputLocation: C:\<redacted>\spa-vanilla\src
 - files:
   - 0: C:\<redacted>\spa-vanilla\.github\workflows\azure-static-web-apps-thankful-island-0c2e35803.yml
User workflow config:
 - appBuildCommand: <undefined>
 - apiBuildCommand: <undefined>
 - appLocation: C:\<redacted>\spa-vanilla
 - apiLocation: C:\<redacted>\spa-vanilla\api
 - outputLocation: C:\<redacted>\spa-vanilla\src
- files:
  - 0: C:\<redacted>\spa-vanilla\.github\workflows\azure-static-web-apps-thankful-island-0c2e35803.yml
Starting the SWA emulator with the following configuration:
- ssl:
  - 0: false
  - 1: <undefined>
  - 2: <undefined>
- env:
  - SWA_RUNTIME_CONFIG_LOCATION: C:\<redacted>\spa-vanilla
  - SWA_RUNTIME_WORKFLOW_LOCATION: C:\<redacted>\spa-vanilla\.github\workflows\azure-static-web-apps-thankful-island-0c2e35803.yml
  - SWA_CLI_DEBUG: silly
  - SWA_CLI_API_PORT: 7071
  - SWA_CLI_APP_LOCATION: C:\<redacted>\spa-vanilla
  - SWA_CLI_OUTPUT_LOCATION: C:\<redacted>\spa-vanilla\src
  - SWA_CLI_API_LOCATION: C:\<redacted>\spa-vanilla\api
  - SWA_CLI_HOST: localhost
  - SWA_CLI_PORT: 4280
  - SWA_CLI_APP_SSL: false
  - SWA_CLI_APP_SSL_CERT: <undefined>
  - SWA_CLI_APP_SSL_KEY: <undefined>
  - SWA_CLI_STARTUP_COMMAND: <undefined>
  - SWA_CLI_VERSION: 1.0.3
  - SWA_CLI_SERVER_TIMEOUT: 60
  - SWA_CLI_OPEN_BROWSER: false
- commands:
  - swa: node "C:\Users\peter\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\dist\msha\server.js"
  - api: cd "C:\<redacted>\spa-vanilla\api" && C:\Users\peter\.swa\core-tools\v4\func start --cors "*" --port 7071
  - run: <undefined>
[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]
[swa]
[swa] Using workflow file:
[swa]   C:\<redacted>\spa-vanilla\.github\workflows\azure-static-web-apps-thankful-island-0c2e35803.yml
[api] [2022-11-08T14:32:37.538Z] File 'C:\Program Files (x86)\dotnet\dotnet.exe' is not found, 'dotnet' invocation will rely on the PATH environment variable.
[swa] No staticwebapp.config.json found in current project
[swa] Validating dev server config:
[swa]  - url: http://localhost:7071
[swa]  - timeout: 60
[swa] Checking if localhost:7071 is accepting TCP connections...
[swa] - Waiting for http://localhost:7071 to be ready
[api] [2022-11-08T14:32:37.806Z] File 'C:\Program Files (x86)\dotnet\dotnet.exe' is not found, 'dotnet' invocation will rely on the PATH environment variable.
[api]
[api] Functions:
[api]
[api]   message:  http://localhost:7071/api/message
[api]
[api] For detailed output, run func with --verbose flag.
[api] [2022-11-08T14:32:38.320Z] Worker process started and initialized.

log from running swa start src --verbose=silly

Welcome to Azure Static Web Apps CLI (1.0.3)

Getting config file options from swa-cli.config.json...
Config file does not exist at C:\<redacted>\spa-vanilla\swa-cli.config.json
***********************************************************************
* WARNING: This emulator may not match the cloud environment exactly. *
* Always deploy and test your app in Azure.                           *
***********************************************************************

Checking if localhost:4280 is accepting TCP connections...
Port 4280 is available. Use it.
Resolved port number: 4280
Resolving outputLocation=src full path...
Resolved outputLocation:
  C:\<redacted>\spa-vanilla\src
Trying to read workflow config with values:
 - appLocation: C:\<redacted>\spa-vanilla
 - outputLocation: C:\<redacted>\spa-vanilla\src
 - apiLocation: <undefined>
Found a SWA workflow file: C:\<redacted>\spa-vanilla\.github\workflows\azure-static-web-apps-thankful-island-0c2e35803.yml
 - app_build_command: <undefined>
 - api_build_command: <undefined>
 - app_location: /src
 - output_location: /src
 - api_location: api
Validating user workflow config (BEFORE):
 - appLocation: C:\<redacted>\spa-vanilla
 - outputLocation: C:\<redacted>\spa-vanilla\src
 - apiLocation: <undefined>
Validating user workflow config (AFTER):
 - appLocation: C:\<redacted>\spa-vanilla
 - apiLocation: <undefined>
 - outputLocation: C:\<redacted>\spa-vanilla\src
Workflow configuration:
- config:
  - appBuildCommand: <undefined>
  - apiBuildCommand: <undefined>
  - appLocation: C:\<redacted>\spa-vanilla
  - apiLocation: <undefined>
  - outputLocation: C:\<redacted>\spa-vanilla\src
 - files:
   - 0: C:\<redacted>\spa-vanilla\.github\workflows\azure-static-web-apps-thankful-island-0c2e35803.yml
User workflow config:
 - appBuildCommand: <undefined>
 - apiBuildCommand: <undefined>
 - appLocation: C:\<redacted>\spa-vanilla
 - apiLocation: <undefined>
 - outputLocation: C:\<redacted>\spa-vanilla\src
- files:
  - 0: C:\<redacted>\spa-vanilla\.github\workflows\azure-static-web-apps-thankful-island-0c2e35803.yml
Starting the SWA emulator with the following configuration:
- ssl:
  - 0: false
  - 1: <undefined>
  - 2: <undefined>
- env:
  - SWA_RUNTIME_CONFIG_LOCATION: C:\<redacted>\spa-vanilla
  - SWA_RUNTIME_WORKFLOW_LOCATION: C:\<redacted>\spa-vanilla\.github\workflows\azure-static-web-apps-thankful-island-0c2e35803.yml
  - SWA_CLI_DEBUG: silly
  - SWA_CLI_API_PORT: 7071
  - SWA_CLI_APP_LOCATION: C:\<redacted>\spa-vanilla
  - SWA_CLI_OUTPUT_LOCATION: C:\<redacted>\spa-vanilla\src
  - SWA_CLI_API_LOCATION: <undefined>
  - SWA_CLI_HOST: localhost
  - SWA_CLI_PORT: 4280
  - SWA_CLI_APP_SSL: false
  - SWA_CLI_APP_SSL_CERT: <undefined>
  - SWA_CLI_APP_SSL_KEY: <undefined>
  - SWA_CLI_STARTUP_COMMAND: <undefined>
  - SWA_CLI_VERSION: 1.0.3
  - SWA_CLI_SERVER_TIMEOUT: 60
  - SWA_CLI_OPEN_BROWSER: false
- commands:
  - swa: node "C:\Users\peter\AppData\Roaming\npm\node_modules\@azure\static-web-apps-cli\dist\msha\server.js"
  - api: <undefined>
  - run: <undefined>
[swa]
[swa] Using workflow file:
[swa]   C:\<redacted>\spa-vanilla\.github\workflows\azure-static-web-apps-thankful-island-0c2e35803.yml
[swa] No staticwebapp.config.json found in current project
[swa]
[swa] Serving static content:
[swa]   C:\<redacted>\spa-vanilla\src
[swa]
[swa] Azure Static Web Apps emulator started at http://localhost:4280. Press CTRL+C to exit.
[swa]
[swa]

Desktop (please complete the following information):

  • OS: Windows: 10
  • @azure/static-web-apps-cli@1.0.3
  • azure-functions-core-tools@4.0.4865
@sgollapudi77 sgollapudi77 added the status: investigating The team is investigating the issues label Nov 9, 2022
@Reshmi-Sriram
Copy link
Member

Hi @peterfearn,
We are investigating this and will get back to you with further questions for clarification!

@rupareddy5-21
Copy link
Contributor

Hi @peterfearn, we couldn't repro the issue. Are you using the sample repo provided in the documentation or own repository? If using your own repository, can you provide more details?

@maxmalynowsky
Copy link

I'm having the same issues with a TypeScript API.
OS: macOS 13.0
Repo: https://github.com/Space4Good/nor-map
Command: swa start http://localhost:5173 --run 'npm run dev' --api-location api

Dropping the --api-location allows static content to be served.

[run] 
[run] > nor-map@0.0.1 dev
[run] > vite dev
[run] 
[api] 
[api] Azure Functions Core Tools
[api] Core Tools Version:       4.0.4865 Commit hash: N/A  (64-bit)
[api] Function Runtime Version: 4.12.2.19454
[api] 
[swa] 
[swa] Using workflow file:
[swa]   /Users/computer/GitHub/Space4Good/nor-map/.github/workflows/azure-static-web-apps-red-flower-0b56d4a03.yml
[run] 
[run]   VITE v3.2.3  ready in 382 ms
[run] 
[run]   ➜  Local:   http://localhost:5173/
[run]   ➜  Network: use --host to expose
[swa] 
[swa] Found configuration file:
[swa]   /Users/computer/GitHub/Space4Good/nor-map/staticwebapp.config.json
[swa] 
[swa] - Waiting for http://localhost:7071 to be ready
[api] [2022-11-09T21:38:42.615Z] Worker process started and initialized.
[api] 
[api] Functions:
[api] 
[api]   upload: [POST] http://localhost:7071/api/upload
[api] 
[api] For detailed output, run func with --verbose flag.
[api] [2022-11-09T21:38:47.379Z] Host lock lease acquired by instance ID '0000000000000000000000003249DC52'.
[swa] ✖ Waiting for http://localhost:7071 to be ready
[swa] ✖ Could not connect to "http://localhost:7071". Is the server up and running?
[swa] node "/Users/computer/GitHub/Space4Good/nor-map/node_modules/@azure/static-web-apps-cli/dist/msha/server.js" exited with code 0
--> Sending SIGTERM to other processes..
[api] [2022-11-09T21:39:41.927Z] Language Worker Process exited. Pid=39647.
[api] [2022-11-09T21:39:41.927Z] node exited with code 143 (0x8F). .
[run] cd "/Users/computer/GitHub/Space4Good/nor-map" && npm run dev exited with code SIGTERM
--> Sending SIGTERM to other processes..
[api] [2022-11-09T21:39:42.066Z] Worker process started and initialized.

@maxmalynowsky
Copy link

For reference, running the API as a separate process works as expected.

OS: macOS 13.0
Repo: https://github.com/Space4Good/nor-map/tree/main/api
Command: npm start

> api@1.0.0 prestart
> npm run build


> api@1.0.0 build
> tsc


> api@1.0.0 start
> func start


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-09T21:45:37.632Z] Worker process started and initialized.

Functions:

        upload: [POST] http://localhost:7071/api/upload

For detailed output, run func with --verbose flag.
[2022-11-09T21:45:42.409Z] Host lock lease acquired by instance ID '0000000000000000000000003249DC52'.
[2022-11-09T21:46:08.896Z] Executing 'Functions.upload' (Reason='This function was programmatically called via the host APIs.', Id=72d23f35-f3af-4748-8c4c-43222408cf25)
[2022-11-09T21:46:09.779Z] Executed 'Functions.upload' (Succeeded, Id=72d23f35-f3af-4748-8c4c-43222408cf25, Duration=897ms)

@peterfearn
Copy link
Author

peterfearn commented Nov 10, 2022

Hi @rupareddy5-21

I've made the repo I'm using public - https://github.com/peterfearn/spa-vanilla - it was just generated from here https://github.com/staticwebdev/vanilla-basic/generate

I've also had no luck when manually creating it too:

mkdir swa-test

cd swa-test

swa init

Choose a configuration name: » swa-test

√ Are these settings correct? ... no
√ What's your app location? ... src
√ What's your build output location? ...
√ What's your API location? (optional) ... api
√ What command do you use to build your app? (optional) ...
√ What command do you use to build your API? (optional) ...
√ What command do you use to run your app for development? (optional) ...
√ What is your development server url (optional) ...

Configuration successfully saved to swa-cli.config.json.

Get started with the following commands:

  • Use swa start to run your app locally.
  • Use swa deploy to deploy your app to Azure.

I've added basic files into the api and src directories (I've created a repo with them all https://github.com/peterfearn/swa-test)

then when I do

swa start src

I get the site running

if I do

swa start src --api-location api

I get the api running but not the site

@maxmalynowsky
Copy link

It seems my issue is a duplicate of this one: #598

@rupareddy5-21
Copy link
Contributor

Hi, @peterfearn, @maxmalynowsky, I've tried with both your repos, and I didn't find any issue. I'm using the same versions
azure/static-web-apps-cli@1.0.3
azure-functions-core-tools@4.0.4865

@maxmalynowsky
Copy link

@rupareddy5-21, my issue only appeared when using Node 18, Node 16 runs without any problems. When downgrading to 1.0.2, I noticed there was an error when trying to install the CLI with Node 18, but this error goes away with 1.0.3. Until this issue is resolved, it could be useful to add "node": ">=14.0.0 <18.0.0", under engines in package.json.

@peterfearn
Copy link
Author

peterfearn commented Nov 15, 2022

I have downgraded node to 16.18.1 and it works now.

I was previously running node 18.12.1

@cmdkeen
Copy link

cmdkeen commented Nov 15, 2022

Same for me - downgrading to node 16 immediately solved the problem

@rupareddy5-21
Copy link
Contributor

Thanks @peterfearn, @maxmalynowsky, we'll work on it. We're closing the issue, please feel free to raise concerns or re-open this if you're facing any issues.

@sgollapudi77
Copy link
Contributor

Please track the original issue here- #598.

@sgollapudi77 sgollapudi77 added the status: duplicate This issue or pull request already exists label Nov 16, 2022
@scafaria
Copy link

I'm trying node 16 also and have the problem (or at least very similar). I can hit the web app at the 7175 port below. But if I try at 4280 it says "the site can't be reached". I am using Node 16 and Chrome on Windows 11. (Note: I'm new to this; following a tutorial). Thanks.

Here is the profiles node of my Client launchsettings.json. I've tried with and without the launchUrl delared.

"profiles": {
"Client": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "http://localhost:4280",
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7175;http://localhost:5023",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}

And here is the output

c:\PositiveSum\Code\Samples\Scratchest>swa start https://localhost:7175 --verbose=silly

Welcome to Azure Static Web Apps CLI (1.0.3)

Getting config file options from swa-cli.config.json...
Config file does not exist at c:\PositiveSum\Code\Samples\Scratchest\swa-cli.config.json


  • WARNING: This emulator may not match the cloud environment exactly. *
  • Always deploy and test your app in Azure. *

Checking if localhost:4280 is accepting TCP connections...
Port 4280 is available. Use it.
Resolved port number: 4280
appDevserverUrl provided, we will try connect to dev server at .
Trying to read workflow config with values:

  • appLocation: c:\PositiveSum\Code\Samples\Scratchest
  • outputLocation: https://localhost:7175
  • apiLocation:
    No workflow config folder found at c:\PositiveSum\Code\Samples\Scratchest.github\workflows
    Validating user workflow config (BEFORE):
  • appLocation: c:\PositiveSum\Code\Samples\Scratchest
  • outputLocation: https://localhost:7175
  • apiLocation:
    Validating user workflow config (AFTER):
  • appLocation: c:\PositiveSum\Code\Samples\Scratchest
  • apiLocation:
  • outputLocation: https://localhost:7175
    User workflow config:
  • appLocation: c:\PositiveSum\Code\Samples\Scratchest
  • apiLocation:
  • outputLocation: https://localhost:7175
    Starting the SWA emulator with the following configuration:
  • ssl:
    • 0: false
    • 1:
    • 2:
  • env:
    • SWA_RUNTIME_CONFIG_LOCATION: c:\PositiveSum\Code\Samples\Scratchest
    • SWA_RUNTIME_WORKFLOW_LOCATION:
    • SWA_CLI_DEBUG: silly
    • SWA_CLI_API_PORT: 7071
    • SWA_CLI_APP_LOCATION: c:\PositiveSum\Code\Samples\Scratchest
    • SWA_CLI_OUTPUT_LOCATION: https://localhost:7175
    • SWA_CLI_API_LOCATION:
    • SWA_CLI_HOST: localhost
    • SWA_CLI_PORT: 4280
    • SWA_CLI_APP_SSL: false
    • SWA_CLI_APP_SSL_CERT:
    • SWA_CLI_APP_SSL_KEY:
    • SWA_CLI_STARTUP_COMMAND:
    • SWA_CLI_VERSION: 1.0.3
    • SWA_CLI_SERVER_TIMEOUT: 60
    • SWA_CLI_OPEN_BROWSER: false
  • commands:
    • swa: node "C:\Users\Vince Scafaria\AppData\Roaming\npm\node_modules@azure\static-web-apps-cli\dist\msha\server.js"
    • api:
    • run:
      [swa] No staticwebapp.config.json found in current project
      [swa] Validating dev server config:
      [swa] - url: https://localhost:7175
      [swa] - timeout: 60
      [swa] Checking if localhost:7175 is accepting TCP connections...
      [swa] - Waiting for https://localhost:7175 to be ready
      [swa] √ Connected to https://localhost:7175 successfully
      [swa]
      [swa] Using dev server for static content:
      [swa] https://localhost:7175
      [swa]
      [swa] Azure Static Web Apps emulator started at http://localhost:4280. Press CTRL+C to exit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate This issue or pull request already exists status: investigating The team is investigating the issues
Projects
None yet
Development

No branches or pull requests

7 participants