Skip to content

Commit

Permalink
Fix redis and read only db
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffm2001 committed Oct 14, 2024
1 parent 7ce0e22 commit aec5dfc
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/server/models/thinky.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import bluebird from "bluebird";
import knex from "knex";
import config from "../knex-connect";

const { parse: pgDbUrlParser } = require("pg-connection-string");

// Instantiate the rethink-knex-adapter using the config defined in
// /src/server/knex.js.
const knexConn = knex(config);
Expand All @@ -14,11 +16,18 @@ if (
) {
const roConfig = {
...config,
connection: process.env.READONLY_DATABASE_URL || {
connection: {
...config.connection,
host: process.env.DB_READONLY_HOST
}
};

if (process.env.READONLY_DATABASE_URL) {
roConfig.connection = pgDbUrlParser(process.env.READONLY_DATABASE_URL);
const useSSL = process.env.DB_USE_SSL === "1" || process.env.DB_USE_SSL.toLowerCase() === "true";
roConfig.connection.ssl = useSSL ? { rejectUnauthorized: false } : false;
}

thinkyConn.r.knexReadOnly = knex(roConfig);
} else {
thinkyConn.r.knexReadOnly = thinkyConn.r.knex;
Expand Down Expand Up @@ -51,10 +60,9 @@ if (redisUrl) {
if (/rediss/.test(redisSettings.url)) {
// secure redis protocol for Redis 6.0+
// https://devcenter.heroku.com/articles/securing-heroku-redis#using-node-js
redisSettings.tls = {
redisSettings.socket = {
tls: true,
rejectUnauthorized: false,
requestCert: true,
agent: false
};
}
if (process.env.REDIS_JSON) {
Expand Down

0 comments on commit aec5dfc

Please sign in to comment.