简体   繁体   中英

Invalid URL that works in staging server but fails in production

I just spent a whole night figuring out why our production server had a bug that was missed in our staging servers. And this morning, I finally narrowed it down and nailed it to this piece of code:

url = [ database.protocol, '//' + database.host, database.port, ].join(':');
url = [ url, database.db ].join('/');

Yeah. How on earth could this actually work? Well, in staging it showed:

http://:localhost:5984/fo

But in master it showed

http://:10.x.x.x:5984/fo (x is a number)

The former worked, but the latter didn't. This is where my knowledge on URLs fail me. How on earth is the former valid but the latter not?

EDIT:

To be clear, I think both URLs should be invalid, that this is a bug that should be caught in my staging server. I just want to know why the former URL (:localhost) is interpreted as valid but the latter isn't.

localhost is (almost always) 127.0.0.1 . 127.0.0.1 is very different to 10.xxx .

If the server is listening on localhost , only connections coming from the server itself will be received. Therefore even entering the server's IP is not enough to connect to it from the outside.

Make sure the server is listening on its network IP, rather than the loopback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM