Closed antonkomarev closed 4 years ago
I don't think Node.js supports wildcard subdomains. Can't you just use DNS?
You can create DNS records for tenant1.test.localhost
and tenant2.test.localhost
which resolve to 0.0.0.0
, 127.0.0.1
or another valid IP address for your server.
Subdomains are generated with random number, so there is no way to define all the possible cases. Usually tenant names contains random number at the end: tenant12321.test.localhost
If you run the ws
command, the server will accept connections from any hostname which resolves to a valid IP address for your computer.
What do you need me to do? I'm not clear. You can already use any hostname (e.g. tenant12321.test.localhost
) but the hostname must be correctly set up in DNS. I can't help you with your "random number" issue - a hostname will only work if it is configured in DNS.
If I'm defining strict hostname it works as expected:
ws --hostname test.localhost
This command starts web server which listens requests from http://test.localhost
But I was wanted to write:
ws --hostname *.test.localhost
And from my point of view it should start webserver which listens requests from any subdomain: http://any.test.localhost
, http://sub.test.localhost
, http://domain.test.localhost
, ...
I have configured localhost DNS which allows wildcards and using it by PHP webserver. But your server listens only strictly defined hostnames.
If you run this command:
ws --hostname localhost
the server will accept connections from both localhost
and test.localhost
.
Sorry, one of my apps not working this way and I don't understand why is this happens. I've tried on another app right now and it's working without any issues. Need to try to find the reason.
The value you pass to --hostname
must be a valid DNS entry. This script must return a valid IP.
const dns = require('dns').promises
async function start () {
const addresses = await dns.lookup('test.localhost')
console.log(addresses)
}
start().catch(console.error)
I was wanted to run web server with wildcard subdomains:
This will be very useful to test multi-tenant applications, when each tenant served by the same frontend application, but served on the different subdomains: