Add store factory

This commit is contained in:
Jerko Steiner 2020-03-13 22:03:46 +01:00
parent 41705177c5
commit 170c52eefa
3 changed files with 28 additions and 1 deletions

View File

@ -187,7 +187,7 @@ For more details, see here:
- [x] Reduce production build size by removing Pug. (Fixed in 2d14e5f c743f19)
- [x] Add ability to share files (Fixed in 3877893)
- [ ] Enable node cluster support (to scale vertically).
- [ ] Add Socket.IO support for Redis (to scale horizontally).
- [x] Add Socket.IO support for Redis (to scale horizontally).
- [ ] Generate public keys for each client, and allow each client to accept,
deny, and remember allowed/denied connections to specific peers.
- [ ] Add support for browser push notifications

View File

@ -21,6 +21,16 @@ export interface Config {
cert: string
key: string
}
store?: StoreConfig
}
export type StoreConfig = {
host: string
port: number
prefix: string
type: 'redis'
} | {
type: 'memory'
}
const cfg = readConfig()

View File

@ -0,0 +1,17 @@
import { MemoryStore } from './memory'
import { RedisStore } from './redis'
import Redis from 'ioredis'
import { StoreConfig } from '../config'
import { Store } from './store'
export function createStore(config: StoreConfig = { type: 'memory'}): Store {
switch (config.type) {
case 'redis':
return new RedisStore(new Redis({
host: config.host,
port: config.port,
}), config.prefix)
default:
return new MemoryStore()
}
}