article.js
const router = require("koa-router")()
const ArticleModel = require("../../models/article")
router.get("/api/article",async ctx=>{
var data = await ArticleModel.find({}).sort({_id:-1})
ctx.body={
code:200,
res:data,
msg:"文章相关数据"
}
})
module.exports = router
movie.js
const router = require("koa-router")()
const MovieModel = require("../../models/movie")
router.get("/api/movie",async ctx=>{
var {m} = ctx.query
try{
var data = await MovieModel(m).find({}).sort({rating:-1})
if(data.length){
ctx.body={
code:200,
result:data,
msg:m
}
}else{
throw new Errow("输入的参数不合法")
}
}catch(err){
ctx.body={
code:400,
msg:"请求参数不合法"
}
}
})
module.exports = router