Skip to content

Commit d55d145

Browse files
soletanbooo
soletan
authored andcommitted
fixing support for Unix sockets in native binding
Binding natively connections to Unix sockets failed due to DNS lookups applied on pathname to Unix socket's folder.
1 parent ff77458 commit d55d145

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lib/utils.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,19 @@ var getLibpgConString = function(config, callback) {
7575
params.push("dbname='" + config.database + "'");
7676
}
7777
if(config.host) {
78-
if(config.host != 'localhost' && config.host != '127.0.0.1') {
79-
//do dns lookup
80-
return require('dns').lookup(config.host, function(err, address) {
81-
if(err) return callback(err, null);
82-
params.push("hostaddr="+address)
83-
callback(null, params.join(" "))
84-
})
78+
if (!config.host.indexOf("/")) {
79+
params.push("host=" + config.host);
80+
} else {
81+
if(config.host != 'localhost' && config.host != '127.0.0.1') {
82+
//do dns lookup
83+
return require('dns').lookup(config.host, function(err, address) {
84+
if(err) return callback(err, null);
85+
params.push("hostaddr="+address)
86+
callback(null, params.join(" "))
87+
})
88+
}
89+
params.push("hostaddr=127.0.0.1 ");
8590
}
86-
params.push("hostaddr=127.0.0.1 ");
8791
}
8892
callback(null, params.join(" "));
8993
} else {

0 commit comments

Comments
 (0)