From ea2d2d2effefbe4f24a73287105ac2b69cd436a5 Mon Sep 17 00:00:00 2001 From: "@wwwjim" Date: Wed, 22 Jul 2020 11:34:24 -0700 Subject: [PATCH] postgres: disables SSL in production web to see if that fixes issues --- knexfile.js | 21 +++++++++++++++++++++ node_common/database.js | 4 +++- node_common/environment.js | 8 +++++--- server.js | 1 + 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/knexfile.js b/knexfile.js index caf428dd..45f31f5c 100644 --- a/knexfile.js +++ b/knexfile.js @@ -12,4 +12,25 @@ module.exports = { password: Environment.POSTGRES_ADMIN_PASSWORD, }, }, + www: { + client: "pg", + connection: { + port: 5432, + host: Environment.POSTGRES_HOSTNAME, + database: Environment.POSTGRES_DATABASE, + user: Environment.POSTGRES_ADMIN_USERNAME, + password: Environment.POSTGRES_ADMIN_PASSWORD, + }, + }, + production: { + client: "pg", + connection: { + ssl: true, + port: 5432, + host: Environment.POSTGRES_HOSTNAME, + database: Environment.POSTGRES_DATABASE, + user: Environment.POSTGRES_ADMIN_USERNAME, + password: Environment.POSTGRES_ADMIN_PASSWORD, + }, + }, }; diff --git a/node_common/database.js b/node_common/database.js index 47f0a028..8176f3c8 100644 --- a/node_common/database.js +++ b/node_common/database.js @@ -1,7 +1,9 @@ +import * as Environment from "~/node_common/environment"; + import configs from "~/knexfile"; import knex from "knex"; -const envConfig = configs["development"]; +const envConfig = configs[Environment.NODE]; const Database = knex(envConfig); export default Database; diff --git a/node_common/environment.js b/node_common/environment.js index dc0c8a43..cdd9632b 100644 --- a/node_common/environment.js +++ b/node_common/environment.js @@ -1,10 +1,12 @@ -require("dotenv").config(); - -export const NODE = process.env.NODE_ENV; +export const NODE = process.env.NODE_ENV || "development"; export const IS_PRODUCTION = NODE === "production" || NODE === "www"; export const IS_PRODUCTION_WEB = NODE === "www"; export const PORT = process.env.PORT || 1337; +if (!IS_PRODUCTION_WEB) { + require("dotenv").config(); +} + export const IS_LOCAL_WEB = !IS_PRODUCTION; export const POSTGRES_ADMIN_PASSWORD = process.env.POSTGRES_ADMIN_PASSWORD; export const POSTGRES_ADMIN_USERNAME = process.env.POSTGRES_ADMIN_USERNAME; diff --git a/server.js b/server.js index 18bb0152..54df8329 100644 --- a/server.js +++ b/server.js @@ -19,6 +19,7 @@ const handler = app.getRequestHandler(); app.prepare().then(async () => { const server = express(); + if (Environment.IS_PRODUCTION_WEB) { server.use(compression()); }