From bbcf975d6fb717f7d14208a3bbd00848bfb5bbf9 Mon Sep 17 00:00:00 2001 From: Christine Date: Fri, 9 Aug 2019 10:08:17 +0100 Subject: [PATCH 1/2] added dependency qs --- package-lock.json | 5 +++++ package.json | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 51b51d4..f15abbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2269,6 +2269,11 @@ "integrity": "sha512-xsMgrUwRpuGskEzBFkH8NmTimbZ5PcPup0LA8JJkHIm2IMUbQcpo3yeLNWVrufEYjh8YwtSVh0xz6UeWc5Oh5A==", "dev": true }, + "qs": { + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", + "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==" + }, "rc": { "version": "1.2.8", "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", diff --git a/package.json b/package.json index 700ee50..ccf90fe 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ }, "dependencies": { "env2": "^2.2.2", - "pg": "^7.12.0" + "pg": "^7.12.0", + "qs": "^6.7.0" } } From e1daecd9f493ea8e5171958f79661ada33ec9341 Mon Sep 17 00:00:00 2001 From: Christine Date: Fri, 9 Aug 2019 12:09:19 +0100 Subject: [PATCH 2/2] simplified the pool function in connection.js --- src/database/db_connection.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/database/db_connection.js b/src/database/db_connection.js index 0675060..64e9b2a 100644 --- a/src/database/db_connection.js +++ b/src/database/db_connection.js @@ -9,18 +9,15 @@ if (process.env.NODE_ENV === "test") { if (!DATABASE_URL) throw new Error("Environmental variable DB_URL must be set"); -const params = url.parse(DATABASE_URL); -// console.log('THIS IS PARAMSSSS:', params); -const [username, password] = params.auth.split(":"); +// const params = url.parse(DATABASE_URL); +// // console.log('THIS IS PARAMSSSS:', params); +// const [username, password] = params.auth.split(":"); -const options = { - host: params.hostname, - port: params.port, - database: params.pathname.split("/")[1], - max: process.env.DB_MAX_CONNECTIONS || 2, - user: username, - password, - ssl: params.hostname !== "localhost" -}; +// starsuit code recommendation -module.exports = new Pool(options); +let connectionString = process.env.DATABASE_URL; + +module.exports = new Pool({ + connectionString, + ssl: !connectionString.includes("localhost") +});