I have a Node.js-based deployment script for my application servers. One step in the deployment process is to validate that these application servers are listening on HTTPS
Set the host header for the request:
const https = require('https');
https.get('https://AA.BB.CC.DD', {
headers : { host : 'api.example.com' }
}, res => {
console.log('okay');
}).on('error', e => {
console.log('E', e.message);
});
EDIT: I dug around a bit to see how this works exactly. To allow HTTPS-based virtual hosting, there's a TLS extension called SNI (Server Name Indication). This extension is used by a client to indicate the hostname to which it is trying to connect, so the server can pick the appropriate certificate that belongs to that hostname.
Node's tls module, which is used by https, has an option servername to set this hostname:
https.get('https://AA.BB.CC.DD', {
servername : api.example.com'
}, ...)
However, you still need to pass a Host header too (that's part of the regular HTTP protocol):
https.get('https://AA.BB.CC.DD', {
headers : { host : 'api.example.com' },
servername : 'api.example.com'
}, ...)
To keep things DRY, Node.js will set servername to the Host header, unless it's already set to something else (here).