IATI / js-validator-api

Pure JavaScript IATI validator implementation
GNU Affero General Public License v3.0
1 stars 1 forks source link

`npm run docker:start` can't connect to Redis #483

Open odscjames opened 1 year ago

odscjames commented 1 year ago

Brief Description npm run docker:start can't connect to Redis

Severity Low

Steps to Reproduce in .env set

REDIS_HOSTNAME=redis

Try to run locally with docker

Expected Results/Behaviour You see

{ name: 'redisConnect', value: 'Redis: Connection to redis ready' }

Actual Results/Behaviour

Redis: Unable to connect to the redis database:  ConnectionTimeoutError: Connection timeout

Workaround


diff --git a/config/redis.js b/config/redis.js
index 3c64d21..20545d3 100644
--- a/config/redis.js
+++ b/config/redis.js
@@ -3,9 +3,9 @@ import config from './config.js';

 let connectionOptions = {};
 // https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-best-practices-connection
-if (config.REDIS_KEY && config.REDIS_HOSTNAME) {
+if (config.REDIS_HOSTNAME) {
     connectionOptions = {
-        url: `rediss://${config.REDIS_HOSTNAME}:${config.REDIS_PORT}`,
+        url: `redis://${config.REDIS_HOSTNAME}:${config.REDIS_PORT}`,
         password: config.REDIS_KEY,
         socket: {
             connectTimeout: 5000,

First line change needed as there is no key and we still want to set up all the fancy stuff.

Second line change needed as there is no SSL on the Redis Docker.

I guess we'll need to add a config.REDIS_SSL option

odscjames commented 1 year ago

Or we assume production always uses SSL and dev never does, and after line 29 just add:

} else {
    connectionOptions = { url: `redis://${config.REDIS_HOSTNAME}:${config.REDIS_PORT}` }
}