static-web-apps-cli icon indicating copy to clipboard operation
static-web-apps-cli copied to clipboard

`swa` does not recognize that the api is started when `localhost` resolves to `::1`

Open tlaundal opened this issue 2 years ago • 2 comments

Are you accessing the CLI from the default port :4280 ?

  • [ ] No, I am using a different port number (--port) and accessing the CLI from that port
  • [x] Yes, I am accessing the CLI from port :4280

Describe the bug

When starting my static web app, which has both static files and functions, swa get's stuck waiting for the api on http://localhost:7071 even when the azure function core tools have started the api. It seems this happens because localhost resolves to ::1 (The IPv6 loopback address) on my system, while the api is started on 127.0.0.1 (IPv4 loopback address).

My workaround is to specify the host property in swa-cli.config.json or the --host flag to be 127.0.0.1.

To Reproduce Steps to reproduce the behavior:

  1. Be on a system where localhost resolves to ::1. The most consistent test for this in this case is to see which IP address wait-on resolves (swa uses wait-on) by running npx wait-on -v tcp:localhost:7071
  2. Have a SWA app with both static files and functions. Configure swa-cli.config.json with outputLocation and apiLocation as needed, but without host or similar.
  3. Execute command swa start
  4. After a while, you will get the message
[swa] ✖ Waiting for http://localhost:7071 to be ready
[swa] ✖ Could not connect to "http://localhost:7071". Is the server up and running?

Expected behavior swa should successfully start up. In particular the message below is expected.

[swa] ✔ Connected to http://127.0.0.1:7071 successfully

Desktop (please complete the following information):

  • OS: Fedora Linux 37 Workstation Edition
  • uname -a: Linux xps13 6.1.5-200.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jan 12 15:52:00 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

tlaundal avatar Jan 24 '23 18:01 tlaundal

Please feel free to track the original issue #663

rupareddy5-21 avatar Mar 29 '23 06:03 rupareddy5-21

We see a similar-looking issue in Windows where localhost resolves to IPv6 loopback.

penfold avatar Jun 26 '23 14:06 penfold