Skip to content

Commit a3c0014

Browse files
authored
Merge pull request #2 from hackmdio/fix/move-check-env-to-runtime
fix: move Redis URL environment check to function call and allow it to be passed as a parameter.
2 parents eca482a + 60bb0c8 commit a3c0014

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

src/api.js

Lines changed: 1 addition & 3 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 = env.ensureConf('ysr-redis')) {
107105
this.store = store
108106
this.prefix = prefix
109107
this.consumername = random.uuidv4()

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
}

tests/api.tests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as t from 'lib0/testing'
33
import * as api from '../src/api.js'
44
import * as encoding from 'lib0/encoding'
55
import * as promise from 'lib0/promise'
6+
import * as env from 'lib0/environment'
67
import * as redis from 'redis'
78
import { prevClients, store } from './utils.js'
89

@@ -14,7 +15,7 @@ const redisPrefix = 'ytests'
1415
const createTestCase = async tc => {
1516
await promise.all(prevClients.map(c => c.destroy()))
1617
prevClients.length = 0
17-
const redisClient = redis.createClient({ url: api.redisUrl })
18+
const redisClient = redis.createClient({ url: env.ensureConf('ysr-redis') })
1819
await redisClient.connect()
1920
// flush existing content
2021
const keysToDelete = await redisClient.keys(redisPrefix + ':*')

tests/socketio.tests.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as array from 'lib0/array'
77
import * as redis from 'redis'
88
import * as time from 'lib0/time'
99
import * as jwt from 'lib0/crypto/jwt'
10+
import * as env from 'lib0/environment'
1011
import * as utils from './utils.js'
1112
import { SocketIOProvider } from '../src/y-socket-io/client.js'
1213

@@ -66,7 +67,7 @@ const createApiClient = async () => {
6667
const createTestCase = async (tc) => {
6768
await promise.all(utils.prevClients.map((c) => c.destroy()))
6869
utils.prevClients.length = 0
69-
const redisClient = redis.createClient({ url: api.redisUrl })
70+
const redisClient = redis.createClient({ url: env.ensureConf('ysr-redis') })
7071
await redisClient.connect()
7172
// flush existing content
7273
const keysToDelete = await redisClient.keys(utils.redisPrefix + ':*')

0 commit comments

Comments
 (0)