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 */