|
@@ -3,7 +3,7 @@ import { koaBody } from 'koa-body';
|
|
|
import { copyFile, rm, access, mkdir } from 'node:fs/promises';
|
|
|
import { UPLOAD_DIR, STATIC, SECRET } from '../app.config.mjs';
|
|
|
import jwt from 'jsonwebtoken';
|
|
|
-
|
|
|
+import tokenVerify from '../middlewares/jwt.verify.js';
|
|
|
const router = new Router();
|
|
|
|
|
|
// 通过router实例的一些方法 比如 get、post等去定义 对应请求方法的路由
|
|
@@ -35,13 +35,14 @@ router
|
|
|
};
|
|
|
}
|
|
|
})
|
|
|
- .get('/', async (ctx) => {
|
|
|
+ .get('/', tokenVerify({ secret: SECRET }), async (ctx) => {
|
|
|
let res = await ctx.execute('select * from users;');
|
|
|
+ ctx.status = 200;
|
|
|
ctx.body =
|
|
|
res === false
|
|
|
? {
|
|
|
code: 1,
|
|
|
- msg: '失败',
|
|
|
+ message: '请求超时',
|
|
|
}
|
|
|
: {
|
|
|
code: 0,
|
|
@@ -51,6 +52,7 @@ router
|
|
|
})
|
|
|
.put(
|
|
|
'/upload',
|
|
|
+ tokenVerify({ secret: SECRET }),
|
|
|
koaBody({
|
|
|
multipart: true,
|
|
|
formidable: {
|