Robert Schäfer 290a176407
refactor(backend): types for global config (#8485)
* refactor(backend): types for global config

I saw merge conflicts in these files for #8463 so let's get some parts of this PR into `master` already.

I believe this fixes a small bug. They guard clause didn't ensure that all of REDIS_ configurations were set.

* remove old email mechanism

* refactor(backend: react to @ulfgebhardt's review

See: https://github.com/Ocelot-Social-Community/Ocelot-Social/pull/8485#pullrequestreview-2813528327

* build(backend): optional commit

@ulfgebhardt this is how I tested the configurations. We don't need to include this commit but I wouldn't expect to send out real emails from a `docker-compose` setup.

---------

Co-authored-by: Moriz Wahl <moriz.wahl@gmx.de>
2025-05-07 15:57:35 +02:00

26 lines
625 B
TypeScript

import { RedisPubSub } from 'graphql-redis-subscriptions'
import { PubSub } from 'graphql-subscriptions'
import Redis from 'ioredis'
import CONFIG from '@config/index'
export default () => {
const { REDIS_DOMAIN, REDIS_PORT, REDIS_PASSWORD } = CONFIG
if (!(REDIS_DOMAIN && REDIS_PORT && REDIS_PASSWORD)) {
return new PubSub()
}
const options = {
host: REDIS_DOMAIN,
port: REDIS_PORT,
password: REDIS_PASSWORD,
retryStrategy: (times) => {
return Math.min(times * 50, 2000)
},
}
return new RedisPubSub({
publisher: new Redis(options),
subscriber: new Redis(options),
})
}