Dhaiwat10 / rlp-proxy

The proxy used by @dhaiwat10/react-link-preview to fetch metadata for URLs.
https://www.npmjs.com/package/@dhaiwat10/react-link-preview
34 stars 134 forks source link

Redis crashing the proxy app #18

Closed hocuspocus97 closed 2 years ago

hocuspocus97 commented 2 years ago

Master branch is used.
The proxy is hosted on heroku, supabase is setup and the correct env variables are there.
I get the following error:

$ npm start

> rlp-proxy@1.0.0 start
> node dist/index.js

Server started on port 8080
node:events:504
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
Emitted 'error' event on RedisClient instance at:
    at RedisClient.on_error (C:\Users\marcr\Downloads\rlp-proxy-master\node_modules\redis\index.js:342:14)
    at Socket.<anonymous> (C:\Users\marcr\Downloads\rlp-proxy-master\node_modules\redis\index.js:223:14)
    at Socket.emit (node:events:526:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4078,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 6379
}

I am using the Heroku Data for Redis addon since RedisToGo has been shut down.
Any ideas what I am doing wrong?

hocuspocus97 commented 2 years ago

I managed to solve my issue, commenting in case someone else comes across the same.
The issue is in the following code:
src/index.ts

if (process.env.REDISTOGO_URL) {
  var rtg = require('url').parse(process.env.REDISTOGO_URL);
  var redis = require('redis').createClient(rtg.port, rtg.hostname);

  redis.auth(rtg.auth.split(':')[1]);
} else {
  var redis = require('redis').createClient();
}

process.env.REDISTOGO_URL is written as REDIS_URL in the extension so the code does not use it.