I fumbled to do web development with koa2, and now I find that the front desk is unable to request data. I would like to ask what is unreasonable?
controllers
page.js
models
pageModel.js
public
routes
index.js
views
page.ejs
app.js
/ controllers/page.js
const config = require("../config")
const frontListNewsCenterModel = require("../models/frontListNewsCenter")
module.exports = async (ctx, next) => {
const { companyNews, industryNews } = await frontListNewsCenterModel(ctx);
console.log( companyNews )
await ctx.render("frontListNewsCenter", {
header: {
title: "",
javascript: config.javascript.concat("/js/jqpaginator.min.js", "/js/frontListNewsCenter.js"),
style: config.style.concat("/css/frontListNewsCenter.css"),
},
newBanner: {
imgSrc: "/images/newsbannenr.png",
},
tabNav: {
items: [{
cn: "",
en: "Company news",
}, {
cn: "",
en: "Industry information",
}],
},
companyNews: companyNews,
industryNews: industryNews,
})
}
/ models/pageModel.js
const { getCompanyNewsList, getIndustryInfoList } = require("../config").service
const axios = require("axios")
module.exports = async (ctx, next) => {
const page = ctx.query.page || "1" // page
const size = ctx.query.size || "10" // size
const role = ctx.query.role || "news" // role
let companyNews = []
let industryNews = []
if (role === "news") {
companyNews = await axios.get(getCompanyNewsList, {
params: {
page: page,
size: size
}
})
if (companyNews.data.code === "2000") {
companyNews = companyNews.data.obj
}
}
if (role === "industry") {
industryNews = await axios.get(getIndustryInfoList, {
params: {
page: page,
size: size
}
})
if (industryNews.data.code === "2000") {
industryNews = industryNews.data.obj
}
}
return {
companyNews,
industryNews,
}
}