Add store factory
This commit is contained in:
parent
41705177c5
commit
170c52eefa
@ -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
|
||||
|
||||
@ -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()
|
||||
|
||||
17
src/server/store/factory.ts
Normal file
17
src/server/store/factory.ts
Normal 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()
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user