From 8a17767a28a13e38d10fb3fd770d9618a6ec105d Mon Sep 17 00:00:00 2001 From: Lei OT Date: Tue, 17 Dec 2024 14:10:23 +0800 Subject: [PATCH] =?UTF-8?q?requestHandler=20=E9=9C=80=E8=A6=81=E5=9C=A8?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E9=9D=A2=0Btest:=20mock=20user=20controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wai-server/api/users/user.controller.js | 6 ++---- wai-server/server.js | 7 ++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/wai-server/api/users/user.controller.js b/wai-server/api/users/user.controller.js index 1ba2b7d..09b2206 100644 --- a/wai-server/api/users/user.controller.js +++ b/wai-server/api/users/user.controller.js @@ -36,8 +36,7 @@ exports.getOne = async ctx => { }; exports.getAll = async ctx => { - ctx.status = 200; - ctx.body = db.users; + return db.users; }; exports.createOne = async ctx => { @@ -51,6 +50,5 @@ exports.createOne = async ctx => { }; db.users.push(newUser); const createdUser = db.users.find(user => user.id === id); - ctx.status = 201; - ctx.body = createdUser; + return createdUser; }; diff --git a/wai-server/server.js b/wai-server/server.js index 88dff02..ac9173a 100644 --- a/wai-server/server.js +++ b/wai-server/server.js @@ -24,17 +24,18 @@ server .use(bodyParser) .use(helmet) .use(compress) - .use(cors) - .use(requestHandler); + .use(cors); // Logger server.use(async (ctx, next) => { const start = new Date(); await next(); const ms = new Date() - start; - console.log(`${ctx.method} ${ctx.url} - ${ms}ms`); + console.log(`${ctx.method} ${ctx.url} - ${ctx.status} - ${ms}ms`); }); +server.use(requestHandler); // 必须在最后 + /** * Apply to our server the api router */