-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
46 lines (32 loc) · 977 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"use strict"
global.__base = __dirname + "/"
const ARed = require("ared")
const config = require(`${__base}libs/config`)
const restify = require(`${__base}libs/restify`)
const client = new ARed()
client.replication = config.client.replication
client.writePolicy = config.client.writePolicy
const servers = []
const forwarding = {}
let x = Object.keys(config.servers).length
for (let serverId in config.servers) {
forwarding[serverId] = {
host: config.servers[serverId].host,
port: config.servers[serverId].port
}
servers[serverId] = new ARed()
servers[serverId].listen(
forwarding[serverId],
config.servers[serverId].redis,
null,
() => {
if (--x === 0) {
client.listen(null, null, forwarding, () => {
restify.start()
})
}
}
)
}
require(`${__base}routes`)(restify.server, client)
module.exports = restify.server