1

I have an app created by create-react-app. After building, it generates a html file with some JS and CSS files. The html file looks like

<!doctype html>...<script src="/static/js/main.89f33fbb.chunk.js"></script></body></html>

I try to host those static files by an Express.js server.

const app = express()
  .use(bodyParser.json())
  .use(express.static(path.join(__dirname, '../dist')))

app.listen(5000, '0.0.0.0');

When I try to open http://127.0.0.1:5000 or http://localhost:5000 in browser, it has no issue to load the whole page.

enter image description here

However, when I try to open http://0.0.0.0:5000, it first gets the html file successfully. However, in the following requests, it tries to get JS and CSS files through https that do not exist.

enter image description here

I know the <script src="/static/js/main.89f33fbb.chunk.js"> will try to get the file through https first, but if not exist, I expect it to get through http.

I tried Chrome, Firefox, and Safari in private mode, and the results are same.

Is there any place I did wrong?

Hongbo Miao
  • 45,290
  • 60
  • 174
  • 267
  • Please consult [this](https://superuser.com/questions/949428/whats-the-difference-between-127-0-0-1-and-0-0-0-0), 0.0.0.0 is a special address. – Artur Dec 04 '20 at 21:52
  • You should probably avoid using 0.0.0.0, it has special meaning, see here: https://en.wikipedia.org/wiki/0.0.0.0 – Peter B Dec 04 '20 at 21:53
  • Thanks @PeterB , I am aware of its special meaning. I am using it is actually because I want to wrap it in a docker, and then use it with Kubernetes. I got the suggestion at https://stackoverflow.com/questions/65136017/deployment-pod-cannot-connect-clusterip-service#comment115156305_65136017 – Hongbo Miao Dec 04 '20 at 21:57
  • 1
    You can listen on any addess using 0.0.0.0, but you should not use it to send a request, because 0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown or non-applicable target. Take a look at: https://stackoverflow.com/questions/55565334/what-does-chrome-server-do-when-i-use-0-0-0-0-instead-of-localhost-in-browser, https://superuser.com/questions/949428/whats-the-difference-between-127-0-0-1-and-0-0-0-0, https://serverfault.com/questions/78048/whats-the-difference-between-ip-address-0-0-0-0-and-127-0-0-1 – Lety Dec 04 '20 at 22:19
  • @Lety I think I got what you mean! I would like to accept as an answer once you posted. I will find the right way to handle my case. – Hongbo Miao Dec 04 '20 at 23:52

1 Answers1

1

You can listen on any address using 0.0.0.0, but you should not use it to send a request, because 0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown or non-applicable target.

In the context of servers, 0.0.0.0 means "all IPv4 addresses on the local machine". If a host has two ip addresses, 192.168.1.1 and 10.1.2.1, and a server running on the host listens on 0.0.0.0, it will be reachable at both of those IPs, but if you want to reach the server, you should use one of those Ip.

Take a look at:

Lety
  • 2,511
  • 21
  • 25