我想将获取请求(使用axios)发送到koa路由器,但是从vscode调试视图开始,
路由器ctx.status
始终显示404
,而ctx.message显示"Not Found"
但是我的请求很完美。
我想查询基于mongodb的type
,所以我注册了两个路由器tag
,post
如果type===post
,我们叫next()
,让tag router
处理它
这是我的密码
export default function (this: server) {
queryPost(this.router, this)
queryTag(this.router, this)
}
/**
* type=post&path=postpath
* @param router
*/
async function queryPost(router: Router, server: server) {
router.get('/api/blog', async (ctx, next) => {
let query = ctx.query
let type = query.type
if (type !== 'post') {
return next()
}
let path = query.path
let config = server.config
ctx.body = await server.mgController.query(config.postsCollectionName, {
path: path
})
})
}
/**
* type=tag&name=tagsname
* @param router
*/
async function queryTag(router: Router, server: server) {
let config = server.config
router.get('/api/blog', async (ctx, next) => {
let query = ctx.query
let type = query.type
if (type !== 'tag') {
return next()
}
let name = query.name
ctx.body = await server.mgController.query(config.postsCollectionName, {
'matter.tags':[name]
}, {
sort: {
originDate: 1
},
projection: {
title: 1,
path: 1,
excerpt: 1,
'matter.tags':1,
originDate: 1,
updatedDate: 1
} as TagQueryExcerpt
} as FindOneOptions)
})
}