سؤال

According to the docs, creating a server can optionally listen to a specific host:

server.listen(port, [host], [backlog], [callback])

Begin accepting connections on the specified port and host. If the host is omitted, the server will accept connections directed to any IPv4 address (INADDR_ANY).

So you can listen to a single host, or to any host.

Is there a way to listen to a few specific hosts?

هل كانت مفيدة؟

المحلول

To do this, you must add additional HTTP servers. However, you can use the same callback for each.

If you are using Express, this is as simple as an additional call to app.listen().

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top