static-web-apps-cli
static-web-apps-cli copied to clipboard
`swa` does not recognize that the api is started when `localhost` resolves to `::1`
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:
- Be on a system where
localhostresolves to::1. The most consistent test for this in this case is to see which IP addresswait-onresolves (swauseswait-on) by runningnpx wait-on -v tcp:localhost:7071 - Have a SWA app with both static files and functions. Configure
swa-cli.config.jsonwithoutputLocationandapiLocationas needed, but withouthostor similar. - Execute command
swa start - 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
Please feel free to track the original issue #663
We see a similar-looking issue in Windows where localhost resolves to IPv6 loopback.