You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: pinging the server at 127.0.0.1 when using just the port number (#357)
* add 0.0.0.0 server ci example
* add explicit zero test
* add timeout to the waiting failing demo
* add test and explanation
* run more tests in Node v16
* add debugging
* update what we run on node v16
* switch from localhost to 127.0.0.1 for default host
* prepend localhost and common host names with http
* update readme
* ipv6 test
* update localhost in README snippets
Copy file name to clipboardExpand all lines: README.md
+28-9Lines changed: 28 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,14 +80,17 @@ You can use either `start-server-and-test`, `server-test` or `start-test` comman
80
80
You can use `:` in front of port number like `server-test :8080`, so all these are equivalent
81
81
82
82
```
83
-
start-server-and-test start http://localhost:8080 test
84
-
server-test start http://localhost:8080 test
85
-
server-test http://localhost:8080 test
83
+
start-server-and-test start http://127.0.0.1:8080 test
84
+
server-test start http://127.0.0.1:8080 test
85
+
server-test http://127.0.0.1:8080 test
86
+
server-test 127.0.0.1:8080 test
86
87
start-test :8080 test
87
88
start-test 8080 test
88
89
start-test 8080
89
90
```
90
91
92
+
**Tip:** I highly recommend you specify the full url instead of the port, see the `localhost vs 0.0.0.0 vs 127.0.0.1` section later in this README.
93
+
91
94
### Options
92
95
93
96
If you use convention and name your scripts "start" and "test" you can simply provide URL
@@ -102,7 +105,7 @@ If you use convention and name your scripts "start" and "test" you can simply pr
102
105
}
103
106
```
104
107
105
-
You can also shorten local url to just port, the code below is equivalent to checking `http://localhost:8080`.
108
+
You can also shorten local url to just port, the code below is equivalent to checking `http://127.0.0.1:8080`.
106
109
107
110
```json
108
111
{
@@ -165,7 +168,7 @@ If you want to start the server, wait for it to respond, and then run multiple t
165
168
}
166
169
```
167
170
168
-
The above script `ci` after the `localhost:9000` responds executes the `npm run test:unit` command. Then when it finishes it runs `npm run test:e2e`. If the first or second command fails, the `ci` script fails. Of course, your mileage on Windows might vary.
171
+
The above script `ci` after the `127.0.0.1:9000` responds executes the `npm run test:unit` command. Then when it finishes it runs `npm run test:e2e`. If the first or second command fails, the `ci` script fails. Of course, your mileage on Windows might vary.
169
172
170
173
#### expected
171
174
@@ -198,7 +201,7 @@ Then you can execute tests simply:
starting server using command "http-server -c-1 ."
214
-
and when url "http://localhost:8080" is responding
217
+
and when url "http://127.0.0.1:8080" is responding
215
218
running tests using command "cypress run"
216
219
Starting up http-server, serving .
217
220
...
218
221
```
219
222
223
+
## localhost vs 0.0.0.0 vs 127.0.0.1
224
+
225
+
The latest versions of Node and some web servers listen on host `0.0.0.0` which _no longer means localhost_. Thus if you specify _just the port number_, like `:3000`, this package will try `http://127.0.0.1:3000` to ping the server. A good practice is to specify the full URL you would like to ping.
226
+
227
+
```
228
+
# same as "http://127.0.0.1:3000"
229
+
start-server start 3000 test
230
+
# better
231
+
start-server start http://127.0.0.1:3000 test
232
+
# or
233
+
start-server start http://0.0.0.0:3000 test
234
+
# of course, if your server is listening on localhost
235
+
# you can still set the URL
236
+
start-server start http://localhost:3000 test
237
+
```
238
+
220
239
## Note for yarn users
221
240
222
241
By default, npm is used to run scripts, however you can specify that yarn is used as follows:
@@ -279,8 +298,8 @@ $ DEBUG=start-server-and-test npm run test
0 commit comments