Search code examples
javascriptnode.jsapiip-addressrestify

Configuring domain name instead of IP address while using restify in node app


I am using restify module to generate REST APIs for my application. I want to know how i could configure my domain name directly in this code. I want my ip_addr something like "domainname.com" instead of 127.0.0.1 .

var ip_addr = 'domainname.com';
var port    =  '80';

var connection_string = '127.0.0.1:27017/myapp';
var db = mongojs(connection_string, ['myapp']);
var jobs = db.collection("jobs")

var server = restify.createServer({
    name : "myapp"
});

server.use(restify.queryParser());
server.use(restify.bodyParser());
server.use(restify.CORS());

server.listen(port ,ip_addr, function(){
    console.log('%s listening at %s ', server.name , server.url);
});

I am getting an error EADDRNOTAVAIL whenever I use "domainname.com" instead of "127.0.0.1" can someone help, how can I configure it to my domain name in this node app?


Solution

  • There is some misunderstanding. It asks to specify IP address to listen to.

    Example:

    1. Server has address 100.1.1.2 and 100.1.1.3
    2. mydomain.com is registered to 100.1.1.3
    3. set ip_addr = '100.1.1.3'

    In this case, the server will respond to all requests to this ip, and all domains registered to this IP. Connection through 100.1.1.2 will be timed out.


    Shortly, if you want to listen to domainname.com, just specify the IP it is registered to.

    And if you do not want to worry about the address and listen to all available network interfaces, then do not specify IP address at all:

    server.listen(port, function() { .... Server API