From 9fc813962e03f7b8124276fef5b1b70e4440c49e Mon Sep 17 00:00:00 2001 From: Dimitri Prosper Date: Wed, 12 May 2021 14:40:43 -0400 Subject: [PATCH] updated modules and addressed a pg client issue - updated to the latest modules - fixed an issue encountered with the pg module described here: https://github.com/brianc/node-postgres/issues/2009#issuecomment-753211352 --- sampleapps/nodejs-graphql/package.json | 22 +++++++++---------- sampleapps/nodejs-graphql/src/createTables.js | 19 +++++++++++++--- sampleapps/nodejs-graphql/src/index.js | 19 +++++++++++++--- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/sampleapps/nodejs-graphql/package.json b/sampleapps/nodejs-graphql/package.json index 9c385d8..2786dc4 100644 --- a/sampleapps/nodejs-graphql/package.json +++ b/sampleapps/nodejs-graphql/package.json @@ -1,6 +1,6 @@ { "name": "nodejs-graphql", - "version": "0.1.0", + "version": "0.1.1", "main": "./build/index.js", "repository": "https://github.com/IBM-Cloud/vpc-tutorials.git", "author": "IBM", @@ -11,10 +11,10 @@ "start": "node build/index.js" }, "dependencies": { - "@babel/runtime": "^7.12.13", + "@babel/runtime": "^7.14.0", "axios": "^0.21.1", "body-parser": "^1.19.0", - "chalk": "^4.1.0", + "chalk": "^4.1.1", "compression": "^1.7.4", "cookie-parser": "^1.4.5", "cookie-session": "^1.4.0", @@ -24,22 +24,22 @@ "express-session": "^1.17.1", "fs-extra": "^9.1.0", "graphql": "^15.5.0", - "ibm-cos-sdk": "^1.9.0", + "ibm-cos-sdk": "^1.10.0", "moment": "^2.29.1", "morgan": "^1.10.0", - "pg": "^8.5.1", + "pg": "^8.6.0", "uuid": "^8.3.2", "winston": "^3.3.3", - "winston-daily-rotate-file": "^4.5.0" + "winston-daily-rotate-file": "^4.5.5" }, "devDependencies": { - "@babel/cli": "^7.12.13", - "@babel/core": "^7.12.13", - "@babel/plugin-transform-runtime": "^7.12.15", - "@babel/preset-env": "^7.12.13", + "@babel/cli": "^7.13.16", + "@babel/core": "^7.14.2", + "@babel/plugin-transform-runtime": "^7.14.2", + "@babel/preset-env": "^7.14.2", "rimraf": "^3.0.2" }, "prefixes": { "cookiesPrefix": "vpc:" } -} +} \ No newline at end of file diff --git a/sampleapps/nodejs-graphql/src/createTables.js b/sampleapps/nodejs-graphql/src/createTables.js index 3aafdc2..ba5e5e8 100644 --- a/sampleapps/nodejs-graphql/src/createTables.js +++ b/sampleapps/nodejs-graphql/src/createTables.js @@ -10,11 +10,24 @@ const credentials = pg_credentials[0].credentials; (async function createTables() { let postgresconn = credentials.connection.postgres; + // Connection String is failing starting in pg 8.5.x: https://github.com/brianc/node-postgres/issues/2009#issuecomment-753211352 + // let database_config = { + // connectionString: postgresconn.composed[0], + // ssl: { + // ca: Buffer.from(postgresconn.certificate.certificate_base64, 'base64').toString() + // } + // }; + let database_config = { - connectionString: postgresconn.composed[0], + user: postgresconn.authentication.username, + host: postgresconn.hosts[0].hostname, + database: postgresconn.database, + password: postgresconn.authentication.password, + port: postgresconn.hosts[0].port, ssl: { - ca: Buffer.from(postgresconn.certificate.certificate_base64, 'base64').toString() - } + rejectUnauthorized: true, + ca: Buffer.from(postgresconn.certificate.certificate_base64, 'base64').toString(), + }, }; // Create a pool. diff --git a/sampleapps/nodejs-graphql/src/index.js b/sampleapps/nodejs-graphql/src/index.js index de8b92f..a8565cf 100644 --- a/sampleapps/nodejs-graphql/src/index.js +++ b/sampleapps/nodejs-graphql/src/index.js @@ -73,11 +73,24 @@ app.use( } let postgresconn = pg_credentials[0].credentials.connection.postgres; + // Connection String is failing starting in pg 8.5.x: https://github.com/brianc/node-postgres/issues/2009#issuecomment-753211352 + // let database_config = { + // connectionString: postgresconn.composed[0], + // ssl: { + // ca: Buffer.from(postgresconn.certificate.certificate_base64, 'base64').toString() + // } + // }; + let database_config = { - connectionString: postgresconn.composed[0], + user: postgresconn.authentication.username, + host: postgresconn.hosts[0].hostname, + database: postgresconn.database, + password: postgresconn.authentication.password, + port: postgresconn.hosts[0].port, ssl: { - ca: Buffer.from(postgresconn.certificate.certificate_base64, 'base64').toString() - } + rejectUnauthorized: true, + ca: Buffer.from(postgresconn.certificate.certificate_base64, 'base64').toString(), + }, }; // Create a pool.