|
1 | 1 | const { Server } = require('./lib/server');
|
2 |
| -const { Auth } = require('./lib/auth'); |
| 2 | +const AuthModule = require('./lib/auth-module'); |
| 3 | +const { consoleTransport } = require('./lib/console-transport'); |
| 4 | +const { database } = require('./lib/db'); |
| 5 | +const { ERRORS, ConnectionError } = require('./lib/error'); |
| 6 | +const { logger } = require('./lib/logger'); |
| 7 | +const { sessionService } = require('./lib/session'); |
| 8 | +const { userService } = require('./lib/user'); |
| 9 | +const { validator } = require('./lib/validator'); |
3 | 10 |
|
4 |
| -const clients = new Set(); |
5 |
| -let counter = 0; |
6 |
| - |
7 |
| -setInterval(async () => { |
8 |
| - counter++; |
9 |
| - for (const client of clients) { |
10 |
| - try { |
11 |
| - await client.emit('counter/getCounts', { counter }); |
12 |
| - } catch (error) { |
13 |
| - clients.delete(client); |
14 |
| - } |
15 |
| - } |
16 |
| -}, 2000); |
17 |
| - |
18 |
| -class Counter { |
19 |
| - getCounts(data, client) { |
20 |
| - clients.add(client); |
21 |
| - } |
22 |
| -} |
23 |
| - |
24 |
| -const modules = { |
25 |
| - counter: { |
26 |
| - schema: { |
27 |
| - getCounts: { |
28 |
| - description: 'Получение обновляемого счётчика.', |
29 |
| - public: true, |
30 |
| - emit: { |
31 |
| - description: 'Объект события', |
32 |
| - required: ['counter', 'proper'], |
33 |
| - properties: { |
34 |
| - counter: { |
35 |
| - type: 'Number', |
36 |
| - description: 'Счётчик' |
37 |
| - }, |
38 |
| - proper: { |
39 |
| - type: 'object', |
40 |
| - description: 'Ещё одно свойство', |
41 |
| - required: ['prop1'], |
42 |
| - properties: { |
43 |
| - prop1: { |
44 |
| - type: 'number', |
45 |
| - description: 'Ещё одно свойство внутри!' |
46 |
| - } |
47 |
| - } |
48 |
| - } |
49 |
| - } |
50 |
| - } |
51 |
| - } |
52 |
| - }, |
53 |
| - Module: Counter |
54 |
| - }, |
55 |
| - auth: { |
56 |
| - schema: { |
57 |
| - register: { |
58 |
| - public: true, |
59 |
| - description: 'Регистрация', |
60 |
| - params: { |
61 |
| - required: ['username', 'password'], |
62 |
| - properties: { |
63 |
| - username: { |
64 |
| - type: 'string', |
65 |
| - description: 'Имя пользователя' |
66 |
| - }, |
67 |
| - password: { |
68 |
| - type: 'string' |
69 |
| - } |
70 |
| - } |
71 |
| - }, |
72 |
| - result: { |
73 |
| - required: ['username', 'role', 'createdTime'], |
74 |
| - properties: { |
75 |
| - username: { |
76 |
| - type: 'string' |
77 |
| - }, |
78 |
| - role: { |
79 |
| - type: 'string' |
80 |
| - }, |
81 |
| - createdTime: { |
82 |
| - type: 'string' |
83 |
| - } |
84 |
| - } |
85 |
| - }, |
86 |
| - transport: 'http' |
87 |
| - }, |
88 |
| - login: { |
89 |
| - public: true, |
90 |
| - params: { |
91 |
| - required: ['username', 'password'], |
92 |
| - properties: { |
93 |
| - username: { |
94 |
| - type: 'string' |
95 |
| - }, |
96 |
| - password: { |
97 |
| - type: 'string' |
98 |
| - } |
99 |
| - } |
100 |
| - }, |
101 |
| - result: { |
102 |
| - required: ['username', 'role', 'createdTime'], |
103 |
| - properties: { |
104 |
| - username: { |
105 |
| - type: 'string' |
106 |
| - }, |
107 |
| - role: { |
108 |
| - type: 'string' |
109 |
| - }, |
110 |
| - createdTime: { |
111 |
| - type: 'string' |
112 |
| - } |
113 |
| - } |
114 |
| - }, |
115 |
| - transport: 'http' |
116 |
| - }, |
117 |
| - logout: { |
118 |
| - public: false, |
119 |
| - transport: 'http' |
120 |
| - }, |
121 |
| - me: { |
122 |
| - public: false, |
123 |
| - result: { |
124 |
| - required: ['username', 'role', 'createdTime'], |
125 |
| - properties: { |
126 |
| - username: { |
127 |
| - type: 'string' |
128 |
| - }, |
129 |
| - role: { |
130 |
| - type: 'string' |
131 |
| - }, |
132 |
| - createdTime: { |
133 |
| - type: 'string' |
134 |
| - } |
135 |
| - } |
136 |
| - } |
137 |
| - }, |
138 |
| - changePassword: { |
139 |
| - public: false, |
140 |
| - params: { |
141 |
| - required: ['username', 'oldPassword', 'newPassword'], |
142 |
| - properties: { |
143 |
| - username: { |
144 |
| - type: 'string' |
145 |
| - }, |
146 |
| - oldPassword: { |
147 |
| - type: 'string' |
148 |
| - }, |
149 |
| - newPassword: { |
150 |
| - type: 'string' |
151 |
| - } |
152 |
| - } |
153 |
| - }, |
154 |
| - result: { |
155 |
| - required: ['username', 'role', 'createdTime'], |
156 |
| - properties: { |
157 |
| - username: { |
158 |
| - type: 'string' |
159 |
| - }, |
160 |
| - role: { |
161 |
| - type: 'string' |
162 |
| - }, |
163 |
| - createdTime: { |
164 |
| - type: 'string' |
165 |
| - } |
166 |
| - } |
167 |
| - } |
168 |
| - } |
169 |
| - }, |
170 |
| - Module: Auth |
171 |
| - } |
172 |
| -}; |
173 |
| - |
174 |
| -const server = new Server(modules, { port: 80, host: 'localhost', cors: false }); |
| 11 | +module.exports.AuthModule = AuthModule; |
| 12 | +module.exports.consoleTransport = consoleTransport; |
| 13 | +module.exports.database = database; |
| 14 | +module.exports.ERRORS = ERRORS; |
| 15 | +module.exports.ConnectionError = ConnectionError; |
| 16 | +module.exports.logger = logger; |
| 17 | +module.exports.sessionService = sessionService; |
| 18 | +module.exports.userService = userService; |
| 19 | +module.exports.validator = validator; |
| 20 | +module.exports.Server = Server; |
0 commit comments