@azteam/express 1.2.149 → 1.2.150
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/Server.js
CHANGED
|
@@ -40,6 +40,9 @@ function omitItem(item, guard, allows) {
|
|
|
40
40
|
|
|
41
41
|
class Server {
|
|
42
42
|
constructor(currentDir = '', options = {}) {
|
|
43
|
+
this.redis = null;
|
|
44
|
+
this.messageQueue = null;
|
|
45
|
+
|
|
43
46
|
this.options = options;
|
|
44
47
|
|
|
45
48
|
this.cookieOptions = {
|
|
@@ -229,11 +232,15 @@ class Server {
|
|
|
229
232
|
|
|
230
233
|
}
|
|
231
234
|
|
|
232
|
-
|
|
235
|
+
const resData = {
|
|
233
236
|
success: true,
|
|
234
237
|
data: guardData,
|
|
235
238
|
options: req.resOptions
|
|
236
|
-
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
return res.json(resData);
|
|
237
244
|
};
|
|
238
245
|
|
|
239
246
|
res.cleanCookie = function(data) {
|
|
@@ -1,64 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
import jwt from 'jsonwebtoken';
|
|
3
|
-
|
|
4
|
-
function systemLogin(userData = null) {
|
|
5
|
-
let user = {};
|
|
6
|
-
if (userData) {
|
|
7
|
-
try {
|
|
8
|
-
user = JSON.parse(userData);
|
|
9
|
-
} catch (e) {}
|
|
10
|
-
}
|
|
11
|
-
return user;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default function(cbRefreshToken, cbLoginAPI) {
|
|
1
|
+
export default function(mTimeout = 5) {
|
|
15
2
|
return async function(req, res, next) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
req.user = systemLogin(headers['x-app-user']);
|
|
21
|
-
} else {
|
|
22
|
-
let token = signedCookies.access_token;
|
|
23
|
-
|
|
24
|
-
if (headers.authorization && signedCookies.api_key != headers.authorization) {
|
|
25
|
-
token = headers.authorization;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (token) {
|
|
29
|
-
token = token.replace('Bearer ', '');
|
|
30
|
-
return jwt.verify(token, process.env.SECRET_KEY, async (error, jwtData) => {
|
|
31
|
-
if (error) {
|
|
32
|
-
try {
|
|
33
|
-
let data = null;
|
|
34
|
-
if (error.name === 'TokenExpiredError') {
|
|
35
|
-
if (signedCookies.refresh_token) {
|
|
36
|
-
data = await cbRefreshToken(signedCookies.refresh_token);
|
|
37
|
-
} else if (signedCookies.api_key) {
|
|
38
|
-
data = await cbLoginAPI(signedCookies.api_key);
|
|
39
|
-
}
|
|
40
|
-
} else if (error.name === 'JsonWebTokenError') {
|
|
41
|
-
data = await cbLoginAPI(token);
|
|
42
|
-
}
|
|
43
|
-
if (data) {
|
|
44
|
-
jwtData = jwt.decode(data.access_token);
|
|
45
|
-
res.addCookie({
|
|
46
|
-
'access_token': data.access_token
|
|
47
|
-
});
|
|
48
|
-
res.set('Auth-Token', data.access_token);
|
|
49
|
-
}
|
|
50
|
-
} catch (e) {}
|
|
51
|
-
}
|
|
52
|
-
if (jwtData) {
|
|
53
|
-
req.user = jwtData;
|
|
54
|
-
}
|
|
55
|
-
return next();
|
|
56
|
-
});
|
|
3
|
+
if (req.method === 'GET') {
|
|
4
|
+
const etag_hash = etag(req.url + floorToMinute(Math.floor(Date.now() / 1000), mTimeout));
|
|
5
|
+
if (req.headers['if-none-match'] === etag_hash) {
|
|
6
|
+
return res.status(304).send();
|
|
57
7
|
}
|
|
8
|
+
res.setHeader('ETag', etag_hash);
|
|
58
9
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
10
|
return next();
|
|
62
|
-
}
|
|
63
|
-
|
|
11
|
+
}
|
|
64
12
|
}
|