From 33a1c35ad254fcc78de55956ed680e5b00fc5647 Mon Sep 17 00:00:00 2001 From: guoxiangyang Date: Mon, 11 Jul 2016 05:26:36 +0800 Subject: [PATCH] changed for self signed ssl support (#1072) --- README.md | 22 ++++++++++++++++++++++ lib/connection-parameters.js | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 15607a1..f468913 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,28 @@ It's __highly recommended__ you read the documentation for [pg-pool](https://git [Here is an up & running quickly example](https://github.com/brianc/node-postgres/wiki/Example) +### connect to self signed Postgresql server + +Use following config to connect a Postgresql Server self signed: + +``` +var config = { + database : 'database-name', //env var: PGDATABASE + host : "host-or-ip", //env var: PGPORT + port : 5432, //env var: PGPORT + max : 100, // max number of clients in the pool + idleTimeoutMillis: 30000, + ssl : { + rejectUnauthorized : false, + ca : fs.readFileSync("/path/to/server-certificates/maybe/root.crt").toString(), + key : fs.readFileSync("/path/to/client-key/maybe/postgresql.key").toString(), + cert : fs.readFileSync("/path/to/client-certificates/maybe/postgresql.crt").toString(), + } +}; + +``` + +For more information about `config.ssl` check [TLS (SSL) of nodejs](https://nodejs.org/dist/latest-v4.x/docs/api/tls.html) ## [More Documentation](https://github.com/brianc/node-postgres/wiki) diff --git a/lib/connection-parameters.js b/lib/connection-parameters.js index 4206ff3..f5126a6 100644 --- a/lib/connection-parameters.js +++ b/lib/connection-parameters.js @@ -55,7 +55,7 @@ var ConnectionParameters = function(config) { this.host = val('host', config); this.password = val('password', config); this.binary = val('binary', config); - this.ssl = typeof config.ssl === 'boolean' ? config.ssl : useSsl(); + this.ssl = typeof config.ssl === 'undefined' ? useSsl() : config.ssl; this.client_encoding = val("client_encoding", config); //a domain socket begins with '/' this.isDomainSocket = (!(this.host||'').indexOf('/'));