Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot bind to Fully qualified domain name (FQDN) #4477

Open
croeber8 opened this issue Jan 25, 2024 · 2 comments
Open

Cannot bind to Fully qualified domain name (FQDN) #4477

croeber8 opened this issue Jan 25, 2024 · 2 comments
Labels
support Questions, discussions, and general support

Comments

@croeber8
Copy link

croeber8 commented Jan 25, 2024

Runtime

NodeJS

Runtime version

NodeJS v18

Module version

Hapi v21

Used with

No response

Any other relevant information

No response

How can we help?

Hello, I am trying to upgrade my hapi to v21. I created a simple project just to make sure everything works.

It seems that hapi is not binding when i use the FQDN. It only binds when using 0.0.0.0. I verified this using netstat -a. This is running NodeJS v18 and HapiJS v21 on Windows Server 2019. It is showing in netstat when the FQDN is used but it looks like this

TCP [fe80::688:fda4:99b5:117%6]:8080 DEVAZRVIRRDV03:0 LISTENING

How can I get HAPI to bind to the FQDN.

Here is my code.

const Path = require('path')
const Fs = require('fs')
const Hapi = require('@hapi/hapi');
const host = 'DEVAZRVIRRDV03.dev.dss.local'
//0.0.0.0 works
//const host = '0.0.0.0'

async function Start() {
    try {

        const server = new Hapi.Server({
            host: host,
            port: 8080,
            // tls: {
            //     cert: Fs.readFileSync(Path.resolve('./cer.cer')),
            //     key: Fs.readFileSync(Path.resolve('./key.key'))
            // }
        });
        server.route({
            method: 'GET',
            path: '/test',
            config: {
                handler: async (request, reply) => {
                    console.log('handled')
                    return {
                        message: 'test'
                    };
                }
            }
        });
        console.log('starting')
        await server.start();
        console.log('started')
    } catch (e) {
        console.error(e)
    }
}
Start()
@croeber8 croeber8 added the support Questions, discussions, and general support label Jan 25, 2024
@kanongil
Copy link
Contributor

Hapi doesn't do anything with the FQDN, except pass it to the node http server listen() method, documented here.

FYI, the DNS resolution behaviour has been changed in node to prefer IPv6. Unlike for client connections, there doesn't seem to be any way to tell the listener it to prefer IPv4 when resolving it. You will likely have to use the dns module to pre-resolve it yourself.

@croeber8
Copy link
Author

Yeah, resolving the host using dns.resolve works. Still weird I have to do that though.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

2 participants