Skip to content

Commit 0870468

Browse files
committed
fix: move redis url env check to runtime & allow to pass by arg
1 parent eca482a commit 0870468

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/api.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import * as time from 'lib0/time'
1616
const logWorker = logging.createModuleLogger('@y/redis/api/worker')
1717
// const logApi = logging.createModuleLogger('@y/redis/api')
1818

19-
export const redisUrl = env.ensureConf('ysr-redis')
20-
2119
let ydocUpdateCallback = env.getConf('ydoc-update-callback')
2220
if (ydocUpdateCallback != null && ydocUpdateCallback.slice(-1) !== '/') {
2321
ydocUpdateCallback += '/'
@@ -103,7 +101,7 @@ export class Api {
103101
* @param {string=} prefix
104102
* @param {string=} url
105103
*/
106-
constructor (store, prefix = 'y', url = redisUrl) {
104+
constructor (store, prefix = 'y', url) {
107105
this.store = store
108106
this.prefix = prefix
109107
this.consumername = random.uuidv4()
@@ -120,7 +118,7 @@ export class Api {
120118
this.redisWorkerGroupName = this.prefix + ':worker'
121119
this._destroyed = false
122120
this.redis = redis.createClient({
123-
url,
121+
url: url || env.ensureConf('ysr-redis'),
124122
// scripting: https://github.com/redis/node-redis/#lua-scripts
125123
scripts: {
126124
addMessage: redis.defineScript({

src/socketio.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ class YSocketIOServer {
3535
* @param {import('./storage.js').AbstractStorage} store
3636
* @param {Object} conf
3737
* @param {string} [conf.redisPrefix]
38+
* @param {string} [conf.redisUrl]
3839
* @param {import('./y-socket-io/y-socket-io.js').YSocketIOConfiguration['authenticate']} conf.authenticate
3940
*/
40-
export const registerYSocketIOServer = async (io, store, conf) => {
41-
const app = new YSocketIO(io, { authenticate: conf.authenticate })
42-
const { client, subscriber } = await app.initialize(store, conf)
41+
export const registerYSocketIOServer = async (io, store, { authenticate, redisUrl, redisPrefix }) => {
42+
const app = new YSocketIO(io, { authenticate })
43+
const { client, subscriber } = await app.initialize(store, { redisUrl, redisPrefix })
4344
return new YSocketIOServer(app, client, subscriber)
4445
}

0 commit comments

Comments
 (0)