Koa-router path parameter, what to do in this case?

how can I access / manhour without writing path parameters?
in addition, I would like to ask, do not directly operate the database, only interface forwarding, koa2 can have the concept of model ?
now I am using the chained router.get ("/ manhour", controllers.manhour.get, ) to insert the data into the page, but the page cannot always have only one interface, and it is confusing to write too much, so I would like to ask if there is a model concept
.

routes/api.js

router.get("/api/manhour/:userid/:year/:weeks", controllers.manhour.get)

routes/manhour.js

router.get("/manhour", controllers.manhour.get, async (ctx, next) => {
    await ctx.render("manhour", {
        data: ctx.state.data,
    })
})

controllers/manhour.js

async function get(ctx, next) {
    const { userid, year, weeks } = ctx.params

    const params = {
        userid,
        year,
        weeks,
    }

    await axios.get(getWorkingTimeList, { params })
        .then(res => {
            if (res.status === 200) {
                ctx.state.code = 0
                ctx.state.data = res.data
            } else {
                ctx.state.code = -1
                ctx.state.data = {}
            }
        })

    await next()
}


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

what do you mean you don't have to write path parameters?
model is used to manipulate the database. If you do not manipulate the database, there is no model. If you want to do interface forwarding, generally speaking, nginx can help you. If you need to do it yourself, you can write it in controller.


how can I access / manhour without writing path parameters?

you use the middleware controllers.manhour.get , and then define the receive parameters in it, and then you don't want to pass the parameters now, so how do you do it?

in addition, I would like to ask, do not directly operate the database, only interface forwarding, can koa2 have the concept of model?
now I cram data into the page through chained router.get ('/ manhour', controllers.manhour.get,), but the page can't always have only one interface, and it's confusing to write too much, so I'd like to ask if there is a concept of model
.

koa does not have the concept of model , nor the concept of controller , but since you already have controller in your js code, the concept of model is the same.


I don't quite understand what it means not to write path parameters. Can you describe it in more detail

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-1b3746c-4060a.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-1b3746c-4060a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?