befly 1.2.2 → 1.2.3
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/apis/tool/tokenCheck.js +7 -11
- package/main.js +12 -0
- package/package.json +2 -2
package/apis/tool/tokenCheck.js
CHANGED
|
@@ -5,22 +5,18 @@ import { Jwt } from '../../utils/jwt.js';
|
|
|
5
5
|
|
|
6
6
|
export default Api.POST('令牌检测', false, {}, [], async (befly, ctx) => {
|
|
7
7
|
try {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
{
|
|
15
|
-
detail: jwtData
|
|
16
|
-
}
|
|
17
|
-
);
|
|
8
|
+
const token = ctx.headers?.authorization?.split(' ')[1] || '';
|
|
9
|
+
if (!token) {
|
|
10
|
+
return RNo('令牌不能为空');
|
|
11
|
+
}
|
|
12
|
+
const jwtData = await Jwt.verify(token);
|
|
13
|
+
return RYes('令牌有效');
|
|
18
14
|
} catch (error) {
|
|
19
15
|
befly.logger.error({
|
|
20
16
|
msg: '令牌检测失败',
|
|
21
17
|
error: error.message,
|
|
22
18
|
stack: error.stack
|
|
23
19
|
});
|
|
24
|
-
return RNo('令牌检测失败'
|
|
20
|
+
return RNo('令牌检测失败');
|
|
25
21
|
}
|
|
26
22
|
});
|
package/main.js
CHANGED
|
@@ -319,6 +319,7 @@ class Befly {
|
|
|
319
319
|
hostname: Env.APP_HOST,
|
|
320
320
|
routes: {
|
|
321
321
|
'/': async (req) => {
|
|
322
|
+
const corsOptions = setCorsOptions(req);
|
|
322
323
|
return Response.json(
|
|
323
324
|
{
|
|
324
325
|
code: 0,
|
|
@@ -335,6 +336,7 @@ class Befly {
|
|
|
335
336
|
'/api/*': async (req) => {
|
|
336
337
|
try {
|
|
337
338
|
const corsOptions = setCorsOptions(req);
|
|
339
|
+
|
|
338
340
|
// 直接返回options请求
|
|
339
341
|
if (req.method === 'OPTIONS') {
|
|
340
342
|
return new Response(null, {
|
|
@@ -342,6 +344,7 @@ class Befly {
|
|
|
342
344
|
headers: corsOptions.headers
|
|
343
345
|
});
|
|
344
346
|
}
|
|
347
|
+
|
|
345
348
|
// 初始化请求数据存储
|
|
346
349
|
const ctx = {
|
|
347
350
|
headers: Object.fromEntries(req.headers.entries()),
|
|
@@ -489,6 +492,15 @@ class Befly {
|
|
|
489
492
|
},
|
|
490
493
|
'/*': async (req) => {
|
|
491
494
|
const corsOptions = setCorsOptions(req);
|
|
495
|
+
|
|
496
|
+
// 直接返回options请求
|
|
497
|
+
if (req.method === 'OPTIONS') {
|
|
498
|
+
return new Response(null, {
|
|
499
|
+
status: 204,
|
|
500
|
+
headers: corsOptions.headers
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
|
|
492
504
|
const url = new URL(req.url);
|
|
493
505
|
const filePath = path.join(process.cwd(), 'public', url.pathname);
|
|
494
506
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Buma - 为 Bun 专属打造的 API 接口框架核心引擎",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"README.md",
|
|
50
50
|
"vitest.config.js"
|
|
51
51
|
],
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "092063519e02232d1f60ccf7aa83978f96b940f7"
|
|
53
53
|
}
|