@azteam/express 1.2.147 → 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azteam/express",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.150",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -23,9 +23,13 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/toda93/express#readme",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@azteam/crypto": "
|
|
27
|
-
"@azteam/error": "
|
|
28
|
-
"@azteam/http-client": "
|
|
26
|
+
"@azteam/crypto": "latest",
|
|
27
|
+
"@azteam/error": "latest",
|
|
28
|
+
"@azteam/http-client": "latest",
|
|
29
|
+
"@azteam/rabbitmq-async": "latest",
|
|
30
|
+
"@azteam/redis-async": "latest",
|
|
31
|
+
"@grpc/grpc-js": "1.6.7",
|
|
32
|
+
"@grpc/proto-loader": "0.6.12",
|
|
29
33
|
"body-parser": "1.19.0",
|
|
30
34
|
"cookie-parser": "1.4.4",
|
|
31
35
|
"cors": "2.8.4",
|
package/src/Controller.js
CHANGED
|
@@ -20,9 +20,9 @@ class Controller {
|
|
|
20
20
|
const matches = methodName.match(/^(get|post|put|patch|delete)/);
|
|
21
21
|
if (matches) {
|
|
22
22
|
let path = '/';
|
|
23
|
-
if (methodName.endsWith(
|
|
23
|
+
if (methodName.endsWith('Public')) {
|
|
24
24
|
path += 'public';
|
|
25
|
-
} else if (methodName.endsWith(
|
|
25
|
+
} else if (methodName.endsWith('Trash')) {
|
|
26
26
|
path += 'trash';
|
|
27
27
|
}
|
|
28
28
|
|
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 = {
|
|
@@ -57,8 +60,15 @@ class Server {
|
|
|
57
60
|
this.debug = process.env.NODE_ENV === 'development';
|
|
58
61
|
|
|
59
62
|
this.initController(currentDir);
|
|
63
|
+
}
|
|
60
64
|
|
|
61
65
|
|
|
66
|
+
setMessageQueue(messageQueue) {
|
|
67
|
+
this.messageQueue = messageQueue;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setRedis(redis) {
|
|
71
|
+
this.redis = redis;
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
setCookieOptions(cookieOptions) {
|
|
@@ -222,11 +232,15 @@ class Server {
|
|
|
222
232
|
|
|
223
233
|
}
|
|
224
234
|
|
|
225
|
-
|
|
235
|
+
const resData = {
|
|
226
236
|
success: true,
|
|
227
237
|
data: guardData,
|
|
228
238
|
options: req.resOptions
|
|
229
|
-
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
return res.json(resData);
|
|
230
244
|
};
|
|
231
245
|
|
|
232
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
|
}
|