Koa-router usage problems!

how to get / controllers/frontListNewsCenter.js data

in router.get ("/") of / routes/news.js

/ routes/news.js

const router = require("koa-router")({
    prefix: "/news"
})
const config = require("../config")
const controllers = require("../controllers")

router.get("/", async (ctx, next) => {
    const data = await controllers.frontListNewsCenter.get(ctx, next)
    console.log(111, data) // undefined
    //  /controllers/frontListNewsCenter.js 

    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: [],
        industryNews: [],
    })
})

router.get("/getList", controllers.frontListNewsCenter.get)

module.exports = router

/ controllers/frontListNewsCenter.js

const { getCompanyNewsList, getIndustryInfoList } = require("../config").service
const axios = require("axios")

async function get (ctx, next) {

    const page = ctx.query.page || "1"    // page
    const size = ctx.query.size || "10"   // size
    const role = ctx.query.role || "news" // role
    console.log(222, page, size, role)

    if (role === "news") {
        const companyNews = await axios.get(getCompanyNewsList, {
            params: {
                page: page,
                size: size
            }
        })

        if (companyNews.data.code === "2000") {
            ctx.state.code = 0
            ctx.state.data = companyNews.data.obj
        } else {
            ctx.state.code = -1
            ctx.state.data = []
        }
    }

    if (role === "industry") {
        const industryNews = await axios.get(getIndustryInfoList, {
            params: {
                page: page,
                size: size
            }
        })

        if (industryNews.data.code === "2000") {
            ctx.state.code = 0
            ctx.state.data = industryNews.data.obj
        } else {
            ctx.state.code = -1
            ctx.state.data = []
        }
    }
}

module.exports = {
    get
}
Mar.04,2021

you can only get the data in a function by calling


try this

const get = require('../controllers/frontListNewsCenter')


const data = await get()
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e60dbc-458d2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e60dbc-458d2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?