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