article.js

  1. const router = require("koa-router")()
  2. const ArticleModel = require("../../models/article")
  3. router.get("/api/article",async ctx=>{
  4. var data = await ArticleModel.find({}).sort({_id:-1})
  5. ctx.body={
  6. code:200,
  7. res:data,
  8. msg:"文章相关数据"
  9. }
  10. })
  11. module.exports = router

movie.js

  1. const router = require("koa-router")()
  2. const MovieModel = require("../../models/movie")
  3. router.get("/api/movie",async ctx=>{
  4. var {m} = ctx.query
  5. try{
  6. var data = await MovieModel(m).find({}).sort({rating:-1})
  7. if(data.length){
  8. ctx.body={
  9. code:200,
  10. result:data,
  11. msg:m
  12. }
  13. }else{
  14. throw new Errow("输入的参数不合法")
  15. }
  16. }catch(err){
  17. ctx.body={
  18. code:400,
  19. msg:"请求参数不合法"
  20. }
  21. }
  22. })
  23. module.exports = router