Koa router show 404 even though breakpoint hit and response received successfully












0















I want to send a get request(use axios) to koa router, but from vscode debug view,



router ctx.status always show 404, and ctx.message show "Not Found"



But my request finished perfect..



I want to query mongodb base type, so I register two routers tag,post



if type===post, we call next() and let tag router to process it



enter image description here



Here are my codes



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)
})
}









share|improve this question























  • Default ctx.status is 404,and it will be 200 after ctx.body=something without giving a specific status code. See github.com/koajs/koa/blob/master/lib/response.js#L134

    – lx1412
    Dec 20 '18 at 3:16
















0















I want to send a get request(use axios) to koa router, but from vscode debug view,



router ctx.status always show 404, and ctx.message show "Not Found"



But my request finished perfect..



I want to query mongodb base type, so I register two routers tag,post



if type===post, we call next() and let tag router to process it



enter image description here



Here are my codes



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)
})
}









share|improve this question























  • Default ctx.status is 404,and it will be 200 after ctx.body=something without giving a specific status code. See github.com/koajs/koa/blob/master/lib/response.js#L134

    – lx1412
    Dec 20 '18 at 3:16














0












0








0








I want to send a get request(use axios) to koa router, but from vscode debug view,



router ctx.status always show 404, and ctx.message show "Not Found"



But my request finished perfect..



I want to query mongodb base type, so I register two routers tag,post



if type===post, we call next() and let tag router to process it



enter image description here



Here are my codes



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)
})
}









share|improve this question














I want to send a get request(use axios) to koa router, but from vscode debug view,



router ctx.status always show 404, and ctx.message show "Not Found"



But my request finished perfect..



I want to query mongodb base type, so I register two routers tag,post



if type===post, we call next() and let tag router to process it



enter image description here



Here are my codes



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)
})
}






koa koa-router






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 12:29









toffeetoffee

581110




581110













  • Default ctx.status is 404,and it will be 200 after ctx.body=something without giving a specific status code. See github.com/koajs/koa/blob/master/lib/response.js#L134

    – lx1412
    Dec 20 '18 at 3:16



















  • Default ctx.status is 404,and it will be 200 after ctx.body=something without giving a specific status code. See github.com/koajs/koa/blob/master/lib/response.js#L134

    – lx1412
    Dec 20 '18 at 3:16

















Default ctx.status is 404,and it will be 200 after ctx.body=something without giving a specific status code. See github.com/koajs/koa/blob/master/lib/response.js#L134

– lx1412
Dec 20 '18 at 3:16





Default ctx.status is 404,and it will be 200 after ctx.body=something without giving a specific status code. See github.com/koajs/koa/blob/master/lib/response.js#L134

– lx1412
Dec 20 '18 at 3:16












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467445%2fkoa-router-show-404-even-though-breakpoint-hit-and-response-received-successfull%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467445%2fkoa-router-show-404-even-though-breakpoint-hit-and-response-received-successfull%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin